Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: pkg/http_server/lib/src/http_body_impl.dart

Issue 46043003: The request may be canceled by http_body, thus allow that when testing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http_server/test/http_body_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/lib/src/http_body_impl.dart
diff --git a/pkg/http_server/lib/src/http_body_impl.dart b/pkg/http_server/lib/src/http_body_impl.dart
index 81c7ede54723852a89e333a78a43cd85b832f86e..7682902985018ee15e4f26a76eed74123ab0a5f7 100644
--- a/pkg/http_server/lib/src/http_body_impl.dart
+++ b/pkg/http_server/lib/src/http_body_impl.dart
@@ -21,17 +21,27 @@ class _HttpBodyHandlerTransformer
class _HttpBodyHandlerTransformerSink implements EventSink<HttpRequest> {
final Encoding _defaultEncoding;
final EventSink<HttpRequestBody> _outSink;
+ int _pending = 0;
+ bool _closed = false;
_HttpBodyHandlerTransformerSink(this._defaultEncoding, this._outSink);
void add(HttpRequest request) {
+ _pending++;
_HttpBodyHandler.processRequest(request, _defaultEncoding)
- .then(_outSink.add, onError: _outSink.addError);
+ .then(_outSink.add, onError: _outSink.addError)
+ .whenComplete(() {
+ _pending--;
+ if (_closed && _pending == 0) _outSink.close();
+ });
}
void addError(Object error, [StackTrace stackTrace]) {
_outSink.addError(error, stackTrace);
}
- void close() => _outSink.close();
+ void close() {
+ _closed = true;
+ if (_pending == 0) _outSink.close();
+ }
}
class _HttpBodyHandler {
@@ -44,7 +54,6 @@ class _HttpBodyHandler {
// Try to send BAD_REQUEST response.
request.response.statusCode = HttpStatus.BAD_REQUEST;
request.response.close();
- request.response.done.catchError((_) {});
throw error;
});
}
« no previous file with comments | « no previous file | pkg/http_server/test/http_body_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698