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

Unified Diff: pkg/http/lib/src/utils.dart

Issue 11434018: Make pkg/http use HttpClient.shutdown(force: true). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « pkg/http/lib/src/io_client.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/src/utils.dart
diff --git a/pkg/http/lib/src/utils.dart b/pkg/http/lib/src/utils.dart
index 8431603180c737bb0b8c3ae10b3b7fb2cb944498..5bc9b5f43163e7297f5cf1723d57020e7b138d51 100644
--- a/pkg/http/lib/src/utils.dart
+++ b/pkg/http/lib/src/utils.dart
@@ -144,11 +144,29 @@ Future<List<int>> consumeInputStream(InputStream stream) {
return completer.future;
}
+// TODO(nweiz): this wouldn't be necessary were it not for issue 7013.
+/// Wrap an InputStream in a ListInputStream. This ensures that if the input
+/// stream has invalid onClosed/onError behavior (see issue 7013), that behavior
+/// is papered over.
+InputStream wrapInputStream(InputStream source) {
+ var sink = new ListInputStream();
+ // TODO(nweiz): Due to issuee 3657, pipeInputToInput naturally avoids calling
+ // both onClosed and onError. If 3657 gets fixed before 7013, we'll need to do
+ // that explicitly.
+ pipeInputToInput(source, sink);
+ return sink;
+}
+
/// Takes all input from [source] and writes it to [sink], then closes [sink].
+/// Returns a [Future] that completes when [source] is exhausted.
void pipeInputToInput(InputStream source, ListInputStream sink) {
- source.onClosed = () => sink.markEndOfStream();
+ source.onClosed = sink.markEndOfStream;
source.onData = () => sink.write(source.read());
// TODO(nweiz): propagate source errors to the sink. See issue 3657.
+ // TODO(nweiz): we need to use async here to avoid issue 4974.
+ source.onError = (e) => async.then((_) {
+ throw e;
+ });
}
/// Takes all input from [source] and writes it to [sink], but does not close
« no previous file with comments | « pkg/http/lib/src/io_client.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698