| OLD | NEW |
| (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:async'; | |
| 8 | |
| 9 import 'byte_stream.dart'; | |
| 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.sink], and when the sink is closed the request will end. | |
| 19 class StreamedRequest extends BaseRequest { | |
| 20 /// The sink to which to write data that will be sent as the request body. | |
| 21 /// This may be safely written to before the request is sent; the data will be | |
| 22 /// buffered. | |
| 23 /// | |
| 24 /// Closing this signals the end of the request. | |
| 25 EventSink<List<int>> get sink => _controller.sink; | |
| 26 | |
| 27 /// The controller for [sink], from which [BaseRequest] will read data for | |
| 28 /// [finalize]. | |
| 29 final StreamController<List<int>> _controller; | |
| 30 | |
| 31 /// Creates a new streaming request. | |
| 32 StreamedRequest(String method, Uri url) | |
| 33 : super(method, url), | |
| 34 _controller = new StreamController<List<int>>(sync: true); | |
| 35 | |
| 36 /// Freezes all mutable fields other than [stream] and returns a | |
| 37 /// single-subscription [ByteStream] that emits the data being written to | |
| 38 /// [sink]. | |
| 39 ByteStream finalize() { | |
| 40 super.finalize(); | |
| 41 return new ByteStream(_controller.stream); | |
| 42 } | |
| 43 } | |
| OLD | NEW |