Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library streamed_request; | 5 library streamed_request; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:uri'; | 8 import 'dart:uri'; |
| 9 | 9 |
| 10 import 'base_request.dart'; | 10 import 'base_request.dart'; |
| 11 | 11 |
| 12 /// An HTTP request where the request body is sent asynchronously after the | 12 /// An HTTP request where the request body is sent asynchronously after the |
| 13 /// connection has been established and the headers have been sent. | 13 /// connection has been established and the headers have been sent. |
| 14 /// | 14 /// |
| 15 /// When the request is sent via [BaseClient.send], only the headers and | 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 | 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 | 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 | 18 /// [StreamedRequest.stream], and when the stream is closed the request will |
| 19 /// end. | 19 /// end. |
| 20 class StreamedRequest extends BaseRequest { | 20 class StreamedRequest extends BaseRequest { |
| 21 /// The stream to which to write data that will be sent as the request body. | 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 | 22 /// This may be safely written to before the request is sent; the data will be |
| 23 /// buffered. | 23 /// buffered. |
| 24 /// | 24 /// |
| 25 /// Closing this signals the end of the request. | 25 /// Closing this signals the end of the request. |
| 26 final OutputStream stream; | 26 OutputStream get stream => _outputStream; |
| 27 | |
| 28 /// [stream], stored as a [ListOutputStream]. | |
| 29 final ListOutputStream _outputStream; | |
|
Bob Nystrom
2012/12/17 23:55:15
Why did you have to make this change?
nweiz
2012/12/18 00:25:32
Because onData and read() (referred to in the cons
Bob Nystrom
2012/12/18 00:26:25
If those are only in the ctor, how about just maki
nweiz
2012/12/18 19:21:52
I'll do that in a separate CL.
| |
| 27 | 30 |
| 28 /// The stream from which the [BaseClient] will read the data in [stream] once | 31 /// The stream from which the [BaseClient] will read the data in [stream] once |
| 29 /// the request has been finalized. | 32 /// the request has been finalized. |
| 30 final ListInputStream _inputStream; | 33 final ListInputStream _inputStream; |
| 31 | 34 |
| 32 /// Creates a new streaming request. | 35 /// Creates a new streaming request. |
| 33 StreamedRequest(String method, Uri url) | 36 StreamedRequest(String method, Uri url) |
| 34 : super(method, url), | 37 : super(method, url), |
| 35 stream = new ListOutputStream(), | 38 _outputStream = new ListOutputStream(), |
| 36 _inputStream = new ListInputStream() { | 39 _inputStream = new ListInputStream() { |
| 37 // TODO(nweiz): pipe errors from the output stream to the input stream once | 40 // TODO(nweiz): pipe errors from the output stream to the input stream once |
| 38 // issue 3657 is fixed | 41 // issue 3657 is fixed |
| 39 stream.onData = () => _inputStream.write(stream.read()); | 42 _outputStream.onData = () => _inputStream.write(_outputStream.read()); |
| 40 stream.onClosed = _inputStream.markEndOfStream; | 43 _outputStream.onClosed = _inputStream.markEndOfStream; |
| 41 } | 44 } |
| 42 | 45 |
| 43 /// Freezes all mutable fields other than [stream] and returns an [InputStream ] | 46 /// Freezes all mutable fields other than [stream] and returns an [InputStream ] |
| 44 /// that emits the data being written to [stream]. | 47 /// that emits the data being written to [stream]. |
| 45 InputStream finalize() { | 48 InputStream finalize() { |
| 46 super.finalize(); | 49 super.finalize(); |
| 47 return _inputStream; | 50 return _inputStream; |
| 48 } | 51 } |
| 49 } | 52 } |
| OLD | NEW |