diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index 558b9ca0..d09f170a 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -12,7 +12,7 @@
-
+
@@ -313,7 +313,7 @@
-
+
@@ -474,7 +474,7 @@
-
+
@@ -496,7 +496,7 @@
-
+
@@ -539,7 +539,7 @@
-
+
@@ -562,7 +562,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1cb1fc1c..ea55bec7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,9 +1,7 @@
-
-
-
+
@@ -28,8 +26,8 @@
-
-
+
+
@@ -37,28 +35,55 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -70,7 +95,7 @@
-
+
@@ -79,17 +104,8 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -98,7 +114,7 @@
-
+
@@ -106,15 +122,6 @@
-
-
-
-
-
-
-
-
-
@@ -229,7 +236,6 @@
-
@@ -261,6 +267,7 @@
+
@@ -289,8 +296,6 @@
-
-
@@ -336,6 +341,8 @@
+
+
@@ -665,20 +672,7 @@
-
-
- 1517975306169
-
-
-
- 1517975306169
-
-
- 1517975399809
-
-
-
- 1517975399809
+
1517975513004
@@ -1009,7 +1003,21 @@
1531149879229
-
+
+ 1531151957605
+
+
+
+ 1531151957606
+
+
+ 1531152011317
+
+
+
+ 1531152011317
+
+
@@ -1045,7 +1053,7 @@
-
+
@@ -1057,7 +1065,7 @@
-
+
@@ -1083,8 +1091,7 @@
-
-
+
@@ -1095,6 +1102,7 @@
+
@@ -1108,8 +1116,6 @@
-
-
@@ -1133,7 +1139,9 @@
-
+
+
+
@@ -1141,20 +1149,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1240,13 +1234,6 @@
-
-
-
-
-
-
-
@@ -1390,16 +1377,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1413,14 +1390,14 @@
-
+
-
+
@@ -1433,15 +1410,15 @@
-
-
+
+
-
-
+
+
@@ -1451,7 +1428,7 @@
-
+
@@ -1460,35 +1437,18 @@
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1496,6 +1456,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0124453..b5b580ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+# 1.1.4+11
+* Close the response, etc. *after* finalizers are done.
+
# 1.1.4+10
* Change the zone error handler to take an `Object`
diff --git a/lib/src/http/angel_http.dart b/lib/src/http/angel_http.dart
index 774faab0..be85a714 100644
--- a/lib/src/http/angel_http.dart
+++ b/lib/src/http/angel_http.dart
@@ -273,57 +273,57 @@ class AngelHttp {
: app.responseFinalizers.fold(
new Future.value(), (out, f) => out.then((_) => f(req, res)));
- if (res.isOpen) res.end();
+ return finalizers.then((_) {
+ if (res.isOpen) res.end();
- for (var key in res.headers.keys) {
- request.response.headers.add(key, res.headers[key]);
- }
+ for (var key in res.headers.keys) {
+ request.response.headers.add(key, res.headers[key]);
+ }
- request.response.contentLength = res.buffer.length;
- request.response.headers.chunkedTransferEncoding = res.chunked ?? true;
+ request.response.contentLength = res.buffer.length;
+ request.response.headers.chunkedTransferEncoding = res.chunked ?? true;
- List outputBuffer = res.buffer.toBytes();
+ List outputBuffer = res.buffer.toBytes();
- if (res.encoders.isNotEmpty) {
- var allowedEncodings = req.headers
- .value('accept-encoding')
- ?.split(',')
- ?.map((s) => s.trim())
- ?.where((s) => s.isNotEmpty)
- ?.map((str) {
- // Ignore quality specifications in accept-encoding
- // ex. gzip;q=0.8
- if (!str.contains(';')) return str;
- return str.split(';')[0];
- });
+ if (res.encoders.isNotEmpty) {
+ var allowedEncodings = req.headers
+ .value('accept-encoding')
+ ?.split(',')
+ ?.map((s) => s.trim())
+ ?.where((s) => s.isNotEmpty)
+ ?.map((str) {
+ // Ignore quality specifications in accept-encoding
+ // ex. gzip;q=0.8
+ if (!str.contains(';')) return str;
+ return str.split(';')[0];
+ });
- if (allowedEncodings != null) {
- for (var encodingName in allowedEncodings) {
- Converter, List> encoder;
- String key = encodingName;
+ if (allowedEncodings != null) {
+ for (var encodingName in allowedEncodings) {
+ Converter, List> encoder;
+ String key = encodingName;
- if (res.encoders.containsKey(encodingName))
- encoder = res.encoders[encodingName];
- else if (encodingName == '*') {
- encoder = res.encoders[key = res.encoders.keys.first];
- }
+ if (res.encoders.containsKey(encodingName))
+ encoder = res.encoders[encodingName];
+ else if (encodingName == '*') {
+ encoder = res.encoders[key = res.encoders.keys.first];
+ }
- if (encoder != null) {
- request.response.headers.set('content-encoding', key);
- outputBuffer = res.encoders[key].convert(outputBuffer);
- request.response.contentLength = outputBuffer.length;
- break;
+ if (encoder != null) {
+ request.response.headers.set('content-encoding', key);
+ outputBuffer = res.encoders[key].convert(outputBuffer);
+ request.response.contentLength = outputBuffer.length;
+ break;
+ }
}
}
}
- }
- request.response
- ..statusCode = res.statusCode
- ..cookies.addAll(res.cookies)
- ..add(outputBuffer);
+ request.response
+ ..statusCode = res.statusCode
+ ..cookies.addAll(res.cookies)
+ ..add(outputBuffer);
- return finalizers.then((_) {
return request.response.close().then((_) {
if (req.injections.containsKey(PoolResource)) {
req.injections[PoolResource].release();
diff --git a/pubspec.yaml b/pubspec.yaml
index 9256e1ac..935f2328 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: angel_framework
-version: 1.1.4+10
+version: 1.1.4+11
description: A high-powered HTTP server with DI, routing and more.
author: Tobe O
homepage: https://github.com/angel-dart/angel_framework
diff --git a/test/common.dart b/test/common.dart
index 268bc9be..1c0b4a3b 100644
--- a/test/common.dart
+++ b/test/common.dart
@@ -38,8 +38,8 @@ class IsInstanceOf implements Matcher {
const IsInstanceOf();
@override
- Description describeMismatch(item, Description mismatchDescription,
- Map matchState, bool verbose) {
+ Description describeMismatch(
+ item, Description mismatchDescription, Map matchState, bool verbose) {
return mismatchDescription.add('$item is not an instance of $T');
}