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 |