This commit is contained in:
thosakwe 2017-04-02 15:14:10 -04:00
parent e254d9791d
commit 9683e97603
5 changed files with 35 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# angel_framework # 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) [![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. A high-powered HTTP server with support for dependency injection, sophisticated routing and more.

View file

@ -3,7 +3,6 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:isolate'; import 'dart:isolate';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'common.dart';
main() async { main() async {
int x = 0; int x = 0;

View file

@ -129,6 +129,14 @@ class ResponseContext extends Extensible {
_isOpen = false; _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. /// Sets a response header to the given value, or retrieves its value.
@Deprecated('Please use `headers` instead.') @Deprecated('Please use `headers` instead.')
header(String key, [String value]) { header(String key, [String value]) {
@ -312,6 +320,7 @@ class ResponseContext extends Extensible {
abstract class _LockableBytesBuilder extends BytesBuilder { abstract class _LockableBytesBuilder extends BytesBuilder {
factory _LockableBytesBuilder() => new _LockableBytesBuilderImpl(); factory _LockableBytesBuilder() => new _LockableBytesBuilderImpl();
void _lock(); void _lock();
void _reopen();
} }
class _LockableBytesBuilderImpl implements _LockableBytesBuilder { class _LockableBytesBuilderImpl implements _LockableBytesBuilder {
@ -326,6 +335,11 @@ class _LockableBytesBuilderImpl implements _LockableBytesBuilder {
_closed = true; _closed = true;
} }
@override
void _reopen() {
_closed = false;
}
@override @override
void add(List<int> bytes) { void add(List<int> bytes) {
if (_closed) if (_closed)

View file

@ -153,13 +153,24 @@ class Angel extends AngelBase {
{List middleware: const []}) { {List middleware: const []}) {
if (_flattened != null) { if (_flattened != null) {
print( 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.'); print('This route will be ignored, and no requests will ever reach it.');
} }
return super.addRoute(method, path, handler, middleware: middleware ?? []); 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. /// Loads some base dependencies into the service container.
void bootstrapContainer() { void bootstrapContainer() {
if (runtimeType != Angel) container.singleton(this, as: Angel); if (runtimeType != Angel) container.singleton(this, as: Angel);
@ -400,7 +411,9 @@ class Angel extends AngelBase {
.forEach(_walk); .forEach(_walk);
} }
_walk(_flattened = flatten(this)); if (_flattened == null) _flattened = flatten(this);
_walk(_flattened);
print('Angel is running in production mode.'); print('Angel is running in production mode.');
} }
} }
@ -438,10 +451,14 @@ class Angel extends AngelBase {
_afterProcessed.add(request); _afterProcessed.add(request);
if (!res.willCloseItself) { if (!res.willCloseItself) {
res.reopen();
for (var finalizer in responseFinalizers) { for (var finalizer in responseFinalizers) {
await finalizer(req, res); await finalizer(req, res);
} }
if (res.isOpen) res.end();
for (var key in res.headers.keys) { for (var key in res.headers.keys) {
request.response.headers.add(key, res.headers[key]); request.response.headers.add(key, res.headers[key]);
} }

View file

@ -1,5 +1,5 @@
name: angel_framework 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. description: A high-powered HTTP server with DI, routing and more.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_framework homepage: https://github.com/angel-dart/angel_framework