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

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

Issue 11338054: Add an HTTP library that wraps dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
Index: pkg/http/lib/src/stream_request.dart
diff --git a/pkg/http/lib/src/stream_request.dart b/pkg/http/lib/src/stream_request.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c5f9ff7f95c273d9f70150dbc715ee217b8a6d78
--- /dev/null
+++ b/pkg/http/lib/src/stream_request.dart
@@ -0,0 +1,45 @@
+library stream_request;
+
+import 'dart:io';
+import 'dart:uri';
+
+import 'base_request.dart';
+
+/// An HTTP request where the request body is sent asynchronously after the
+/// connection has been established and the headers have been sent.
+///
+/// When the request is sent via [BaseClient.send], only the headers and
+/// whatever data has already been written to [StreamRequest.stream] will be
+/// sent immediately. More data will be sent as soon as it's written to
+/// [StreamRequest.stream], and when the stream is closed the request will be
+/// ended.
Bob Nystrom 2012/10/31 01:17:44 "will be ended" -> "will end".
nweiz 2012/10/31 18:20:59 Done.
+class StreamRequest extends BaseRequest {
Bob Nystrom 2012/10/31 01:17:44 This reads like a request for a stream and not a r
nweiz 2012/10/31 18:20:59 Done.
+ /// The stream to which to write data that will be sent as the request body.
+ /// This may be safely written to before the request is sent; the data will be
+ /// buffered.
+ ///
+ /// Closing this signals the end of the request.
+ final OutputStream stream;
+
+ /// The stream from which the [BaseClient] will read the data in [stream] once
+ /// the request has been finalized.
+ final ListInputStream _inputStream;
+
+ /// Create a new streaming request.
+ StreamRequest(String method, Uri url)
+ : super(method, url),
+ stream = new ListOutputStream(),
+ _inputStream = new ListInputStream() {
+ // TODO(nweiz): pipe errors from the output stream to the input stream once
+ // issue 3657 is fixed
+ stream.onData = () => _inputStream.write(stream.read());
+ stream.onClosed = _inputStream.markEndOfStream;
+ }
+
+ /// Freeze all mutable fields other than [stream] and return an [InputStream]
+ /// that emits the data being written to [stream].
+ InputStream finalize() {
+ super.finalize();
+ return _inputStream;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698