diff --git a/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml b/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml
new file mode 100644
index 00000000..f13ca17d
--- /dev/null
+++ b/.idea/runConfigurations/encoding_in_encoders_buffer_test_dart.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 08f8be3c..d0c36e6a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,9 +1,24 @@
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -31,33 +46,98 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -65,8 +145,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -88,8 +180,6 @@
- xhr
- accepts
cacheKey
testing
cache
@@ -118,6 +208,8 @@
_useStream
isClosed
HttpHeaders.
+ = false
+ = true
_isClosed
@@ -172,18 +264,12 @@
@@ -333,7 +425,7 @@
-
+
@@ -523,7 +615,7 @@
-
+
@@ -564,6 +656,7 @@
+
@@ -636,14 +729,7 @@
-
-
-
- 1498774662381
-
-
-
- 1498774662382
+
1498830585557
@@ -981,43 +1067,50 @@
1517981171771
-
+
+ 1517981193409
+
+
+
+ 1517981193409
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -1036,7 +1129,7 @@
-
+
@@ -1052,9 +1145,9 @@
-
+
-
+
@@ -1076,7 +1169,6 @@
-
@@ -1101,7 +1193,8 @@
-
+
+
@@ -1110,52 +1203,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1177,13 +1224,6 @@
-
-
-
-
-
-
-
@@ -1252,17 +1292,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -1315,14 +1344,6 @@
-
-
-
-
-
-
-
-
@@ -1331,25 +1352,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1376,14 +1378,6 @@
-
-
-
-
-
-
-
-
@@ -1444,26 +1438,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1488,16 +1462,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1508,30 +1472,171 @@
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/src/http/angel_http.dart b/lib/src/http/angel_http.dart
index 0c0b12b3..156c2890 100644
--- a/lib/src/http/angel_http.dart
+++ b/lib/src/http/angel_http.dart
@@ -88,7 +88,13 @@ class AngelHttp {
if (_closed) return _server;
_closed = true;
_sub?.cancel();
- await app.close();
+
+ // TODO: Remove this try/catch in 1.2.0
+ try {
+ await app.close();
+ } catch(_) {
+
+ }
for (var configurer in app.shutdownHooks) await app.configure(configurer);
return _server;
diff --git a/lib/src/http/http_response_context.dart b/lib/src/http/http_response_context.dart
index 6ed7bd03..b7f13dcb 100644
--- a/lib/src/http/http_response_context.dart
+++ b/lib/src/http/http_response_context.dart
@@ -22,6 +22,11 @@ class HttpResponseContextImpl extends ResponseContext {
return _correspondingRequest;
}
+ @override
+ bool get isOpen {
+ return !_isClosed;
+ }
+
@override
bool get streaming {
return _useStream;
@@ -110,7 +115,12 @@ class HttpResponseContextImpl extends ResponseContext {
@override
Future close() async {
if (_useStream) {
- await io.close();
+ try {
+ await io.close();
+ } catch(_) {
+ // This only seems to occur on `MockHttpRequest`, but
+ // this try/catch prevents a crash.
+ }
}
_isClosed = true;
diff --git a/lib/src/http/response_context.dart b/lib/src/http/response_context.dart
index 8ea3ba72..1cefbac0 100644
--- a/lib/src/http/response_context.dart
+++ b/lib/src/http/response_context.dart
@@ -85,7 +85,7 @@ abstract class ResponseContext implements StreamSink>, StringSink {
}
/// Can we still write to this response?
- bool get isOpen => !!isOpen;
+ bool get isOpen;
/// Returns `true` if a [Stream] is being written directly.
bool get streaming;
diff --git a/performance/hello/main.dart b/performance/hello/main.dart
index a776e60a..6322b678 100644
--- a/performance/hello/main.dart
+++ b/performance/hello/main.dart
@@ -22,9 +22,9 @@ main() async {
}
void start(int id) {
- var app = new Angel.custom(startShared)..lazyParseBodies = true;
+ var app = new Angel()..lazyParseBodies = true;
+ var http = new AngelHttp.custom(app, startShared);
- if (true) {
app.get('/', (req, ResponseContext res) {
res.willCloseItself = true;
res.io
@@ -32,12 +32,7 @@ void start(int id) {
..close();
return false;
});
- } else {
- app.get('/', (req, ResponseContext res) {
- res.useStream();
- res.write('Hello, world!');
- });
- }
+
var oldHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
@@ -45,7 +40,8 @@ void start(int id) {
print(e.stackTrace);
return oldHandler(e, req, res);
};
- app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000).then((server) {
+
+ http.startServer(InternetAddress.LOOPBACK_IP_V4, 3000).then((server) {
print(
'Instance #$id listening at http://${server.address.address}:${server.port}');
});
diff --git a/test/controller_test.dart b/test/controller_test.dart
index e24a81fd..5a8d23a0 100644
--- a/test/controller_test.dart
+++ b/test/controller_test.dart
@@ -60,7 +60,7 @@ main() {
print(app.controllers);
app.dumpTree();
- server = await app.startServer();
+ server = await new AngelHttp(app).startServer();
url = 'http://${server.address.address}:${server.port}';
});
@@ -92,7 +92,7 @@ main() {
return 2;
}, optional: ['bar']));
var rq = new MockHttpRequest('GET', new Uri(path: 'foo'));
- await app.handleRequest(rq);
+ await new AngelHttp(app).handleRequest(rq);
var body = await rq.response.transform(UTF8.decoder).join();
expect(JSON.decode(body), 2);
});
diff --git a/test/di_test.dart b/test/di_test.dart
index c309fe68..793d887d 100644
--- a/test/di_test.dart
+++ b/test/di_test.dart
@@ -27,7 +27,7 @@ main() {
await app.configure(new SingletonController().configureServer);
await app.configure(new ErrandController().configureServer);
- server = await app.startServer();
+ server = await new AngelHttp(app).startServer();
url = "http://${server.address.host}:${server.port}";
});
diff --git a/test/encoders_buffer_test.dart b/test/encoders_buffer_test.dart
index 98bc70ee..be44c15b 100644
--- a/test/encoders_buffer_test.dart
+++ b/test/encoders_buffer_test.dart
@@ -71,8 +71,8 @@ void encodingTests(Angel getApp()) {
test('encodes if explicit', () async {
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
- ..headers.set(HttpHeaders.ACCEPT_ENCODING, 'gzip')
- ..close();
+ ..headers.set(HttpHeaders.ACCEPT_ENCODING, 'gzip');
+ await rq.close();
var rs = rq.response;
await http.handleRequest(rq);
@@ -83,8 +83,8 @@ void encodingTests(Angel getApp()) {
test('only uses one encoder', () async {
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
- ..headers.set(HttpHeaders.ACCEPT_ENCODING, ['gzip', 'deflate'])
- ..close();
+ ..headers.set(HttpHeaders.ACCEPT_ENCODING, ['gzip', 'deflate']);
+ await rq.close();
var rs = rq.response;
await http.handleRequest(rq);
diff --git a/test/general_test.dart b/test/general_test.dart
index 09cc2740..d08b6876 100644
--- a/test/general_test.dart
+++ b/test/general_test.dart
@@ -16,7 +16,7 @@ main() {
..all('*', () => throw new AngelHttpException.notFound());
client = new http.Client();
- server = await app.startServer();
+ server = await new AngelHttp(app).startServer();
url = "http://${server.address.host}:${server.port}";
});
diff --git a/test/hooked_test.dart b/test/hooked_test.dart
index 9102bafa..afe51caa 100644
--- a/test/hooked_test.dart
+++ b/test/hooked_test.dart
@@ -32,8 +32,8 @@ main() {
throw e.error;
};
- server = await app.startServer();
- url = "http://${app.httpServer.address.host}:${app.httpServer.port}";
+ server = await new AngelHttp(app).startServer();
+ url = "http://${server.address.host}:${server.port}";
});
tearDown(() async {
diff --git a/test/precontained_test.dart b/test/precontained_test.dart
index 623bc62c..5c9fb0c6 100644
--- a/test/precontained_test.dart
+++ b/test/precontained_test.dart
@@ -14,7 +14,7 @@ main() {
var rq = new MockHttpRequest('GET', new Uri(path: '/foo'));
rq.close();
- await app.handleRequest(rq);
+ await new AngelHttp(app).handleRequest(rq);
var rs = rq.response;
var body = await rs.transform(UTF8.decoder).join();
expect(body, JSON.encode('bar'));
diff --git a/test/repeat_request_test.dart b/test/repeat_request_test.dart
index 8f1d1c43..f4fb9edf 100644
--- a/test/repeat_request_test.dart
+++ b/test/repeat_request_test.dart
@@ -12,7 +12,7 @@ main() {
test('can request the same url twice', () async {
var app = new Angel()..get('/test/:id', (id) => 'Hello $id');
var rq1 = mk(1), rq2 = mk(2), rq3 = mk(1);
- await Future.wait([rq1, rq2, rq3].map(app.handleRequest));
+ await Future.wait([rq1, rq2, rq3].map(new AngelHttp(app).handleRequest));
var body1 = await rq1.response.transform(UTF8.decoder).join(),
body2 = await rq2.response.transform(UTF8.decoder).join(),
body3 = await rq3.response.transform(UTF8.decoder).join();
diff --git a/test/routing_test.dart b/test/routing_test.dart
index 004bdaf7..d8eb93cd 100644
--- a/test/routing_test.dart
+++ b/test/routing_test.dart
@@ -95,8 +95,9 @@ main() {
app.dumpTree(header: "DUMPING ROUTES:", showMatchers: true);
client = new http.Client();
- await app.startServer(InternetAddress.LOOPBACK_IP_V4, 0);
- url = "http://${app.httpServer.address.host}:${app.httpServer.port}";
+ var server =
+ await new AngelHttp(app).startServer(InternetAddress.LOOPBACK_IP_V4, 0);
+ url = "http://${server.address.host}:${server.port}";
});
tearDown(() async {
diff --git a/test/serialize_test.dart b/test/serialize_test.dart
index d52850b0..ad31a54b 100644
--- a/test/serialize_test.dart
+++ b/test/serialize_test.dart
@@ -18,7 +18,7 @@ main() {
res.serialize({'hello': 'world'}, contentType: ContentType.HTML));
client = new http.Client();
- server = await app.startServer();
+ server = await new AngelHttp(app).startServer();
url = "http://${server.address.host}:${server.port}";
});
diff --git a/test/server_test.dart b/test/server_test.dart
index f952b467..4e67aa47 100644
--- a/test/server_test.dart
+++ b/test/server_test.dart
@@ -62,9 +62,12 @@ main() {
app.startupHooks.add((app) async {
app.configuration['two'] = 2;
});
- await app.startServer();
+
+ var http = new AngelHttp(app);
+ await http.startServer();
expect(app.configuration['two'], 2);
await app.close();
+ await http.close();
});
test('warning when adding routes to flattened router', () {
diff --git a/test/services_test.dart b/test/services_test.dart
index 9f4bd135..a8909aaa 100644
--- a/test/services_test.dart
+++ b/test/services_test.dart
@@ -26,9 +26,9 @@ main() {
print(e.stackTrace);
};
- await app.startServer();
+ var server = await new AngelHttp(app).startServer();
client = new http.Client();
- url = "http://${app.httpServer.address.host}:${app.httpServer.port}";
+ url = "http://${server.address.host}:${server.port}";
});
tearDown(() async {