From 9683e976032b38110f75eb6dab43e514e8058c34 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Sun, 2 Apr 2017 15:14:10 -0400 Subject: [PATCH] 72! --- README.md | 2 +- example/json.dart | 1 - lib/src/http/response_context.dart | 14 ++++++++++++++ lib/src/http/server.dart | 21 +++++++++++++++++++-- pubspec.yaml | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 939a6fd0..9179d255 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angel_framework -[![pub 1.0.0-dev.71](https://img.shields.io/badge/pub-1.0.0--dev.71-red.svg)](https://pub.dartlang.org/packages/angel_framework) +[![pub 1.0.0-dev.72](https://img.shields.io/badge/pub-1.0.0--dev.72-red.svg)](https://pub.dartlang.org/packages/angel_framework) [![build status](https://travis-ci.org/angel-dart/framework.svg)](https://travis-ci.org/angel-dart/framework) A high-powered HTTP server with support for dependency injection, sophisticated routing and more. diff --git a/example/json.dart b/example/json.dart index d84278e5..a8e76a35 100644 --- a/example/json.dart +++ b/example/json.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'dart:io'; import 'dart:isolate'; import 'package:angel_framework/angel_framework.dart'; -import 'common.dart'; main() async { int x = 0; diff --git a/lib/src/http/response_context.dart b/lib/src/http/response_context.dart index 38f17a83..d71dafc9 100644 --- a/lib/src/http/response_context.dart +++ b/lib/src/http/response_context.dart @@ -129,6 +129,14 @@ class ResponseContext extends Extensible { _isOpen = false; } + /// Re-opens a closed response. **NEVER USE THIS IN A PLUGIN**. + /// + /// To preserve your sanity, don't use it ever. This is solely for internal use. + void reopen() { + _buffer._reopen(); + _isOpen = true; + } + /// Sets a response header to the given value, or retrieves its value. @Deprecated('Please use `headers` instead.') header(String key, [String value]) { @@ -312,6 +320,7 @@ class ResponseContext extends Extensible { abstract class _LockableBytesBuilder extends BytesBuilder { factory _LockableBytesBuilder() => new _LockableBytesBuilderImpl(); void _lock(); + void _reopen(); } class _LockableBytesBuilderImpl implements _LockableBytesBuilder { @@ -326,6 +335,11 @@ class _LockableBytesBuilderImpl implements _LockableBytesBuilder { _closed = true; } + @override + void _reopen() { + _closed = false; + } + @override void add(List bytes) { if (_closed) diff --git a/lib/src/http/server.dart b/lib/src/http/server.dart index 757e6e3f..7022c76d 100644 --- a/lib/src/http/server.dart +++ b/lib/src/http/server.dart @@ -153,13 +153,24 @@ class Angel extends AngelBase { {List middleware: const []}) { if (_flattened != null) { print( - 'WARNING: You added a route ($method $path) to the router, after it has been optimized.'); + 'WARNING: You added a route ($method $path) to the router, after it had been optimized.'); print('This route will be ignored, and no requests will ever reach it.'); } return super.addRoute(method, path, handler, middleware: middleware ?? []); } + @override + mount(Pattern path, Router router, {bool hooked: true, String namespace}) { + if (_flattened != null) { + print( + 'WARNING: You added mounted a child router ($path) on the router, after it had been optimized.'); + print('This route will be ignored, and no requests will ever reach it.'); + } + return super + .mount(path, router, hooked: hooked != false, namespace: namespace); + } + /// Loads some base dependencies into the service container. void bootstrapContainer() { if (runtimeType != Angel) container.singleton(this, as: Angel); @@ -400,7 +411,9 @@ class Angel extends AngelBase { .forEach(_walk); } - _walk(_flattened = flatten(this)); + if (_flattened == null) _flattened = flatten(this); + + _walk(_flattened); print('Angel is running in production mode.'); } } @@ -438,10 +451,14 @@ class Angel extends AngelBase { _afterProcessed.add(request); if (!res.willCloseItself) { + res.reopen(); + for (var finalizer in responseFinalizers) { await finalizer(req, res); } + if (res.isOpen) res.end(); + for (var key in res.headers.keys) { request.response.headers.add(key, res.headers[key]); } diff --git a/pubspec.yaml b/pubspec.yaml index 7c68938c..4f865bfb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_framework -version: 1.0.0-dev.71 +version: 1.0.0-dev.72 description: A high-powered HTTP server with DI, routing and more. author: Tobe O homepage: https://github.com/angel-dart/angel_framework