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

Side by Side Diff: pkg/http/lib/src/streamed_request.dart

Issue 11363063: 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/response.dart ('k') | pkg/http/lib/src/streamed_response.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library streamed_request;
6
7 import 'dart:io';
8 import 'dart:uri';
9
10 import 'base_request.dart';
11
12 /// An HTTP request where the request body is sent asynchronously after the
13 /// connection has been established and the headers have been sent.
14 ///
15 /// When the request is sent via [BaseClient.send], only the headers and
16 /// whatever data has already been written to [StreamedRequest.stream] will be
17 /// sent immediately. More data will be sent as soon as it's written to
18 /// [StreamedRequest.stream], and when the stream is closed the request will
19 /// end.
20 class StreamedRequest extends BaseRequest {
21 /// The stream to which to write data that will be sent as the request body.
22 /// This may be safely written to before the request is sent; the data will be
23 /// buffered.
24 ///
25 /// Closing this signals the end of the request.
26 final OutputStream stream;
27
28 /// The stream from which the [BaseClient] will read the data in [stream] once
29 /// the request has been finalized.
30 final ListInputStream _inputStream;
31
32 /// Creates a new streaming request.
33 StreamedRequest(String method, Uri url)
34 : super(method, url),
35 stream = new ListOutputStream(),
36 _inputStream = new ListInputStream() {
37 // TODO(nweiz): pipe errors from the output stream to the input stream once
38 // issue 3657 is fixed
39 stream.onData = () => _inputStream.write(stream.read());
40 stream.onClosed = _inputStream.markEndOfStream;
41 }
42
43 /// Freezes all mutable fields other than [stream] and returns an [InputStream ]
44 /// that emits the data being written to [stream].
45 InputStream finalize() {
46 super.finalize();
47 return _inputStream;
48 }
49 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/response.dart ('k') | pkg/http/lib/src/streamed_response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698