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_response; | 5 library streamed_response; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:io'; | 8 import 'dart:io'; |
8 | 9 |
| 10 import 'byte_stream.dart'; |
9 import 'base_response.dart'; | 11 import 'base_response.dart'; |
10 import 'base_request.dart'; | 12 import 'base_request.dart'; |
| 13 import 'utils.dart'; |
11 | 14 |
12 /// An HTTP response where the response body is received asynchronously after | 15 /// An HTTP response where the response body is received asynchronously after |
13 /// the headers have been received. | 16 /// the headers have been received. |
14 class StreamedResponse extends BaseResponse { | 17 class StreamedResponse extends BaseResponse { |
15 /// The stream from which the response body data can be read. | 18 /// The stream from which the response body data can be read. This should |
16 final InputStream stream; | 19 /// always be a single-subscription stream. |
| 20 final ByteStream stream; |
17 | 21 |
18 /// Creates a new streaming response. | 22 /// Creates a new streaming response. [stream] should be a single-subscription |
| 23 /// stream. |
19 StreamedResponse( | 24 StreamedResponse( |
20 this.stream, | 25 Stream<List<int>> stream, |
21 int statusCode, | 26 int statusCode, |
22 int contentLength, | 27 int contentLength, |
23 {BaseRequest request, | 28 {BaseRequest request, |
24 Map<String, String> headers: const <String>{}, | 29 Map<String, String> headers: const <String>{}, |
25 bool isRedirect: false, | 30 bool isRedirect: false, |
26 bool persistentConnection: true, | 31 bool persistentConnection: true, |
27 String reasonPhrase}) | 32 String reasonPhrase}) |
28 : super( | 33 : super( |
29 statusCode, | 34 statusCode, |
30 contentLength, | 35 contentLength, |
31 request: request, | 36 request: request, |
32 headers: headers, | 37 headers: headers, |
33 isRedirect: isRedirect, | 38 isRedirect: isRedirect, |
34 persistentConnection: persistentConnection, | 39 persistentConnection: persistentConnection, |
35 reasonPhrase: reasonPhrase); | 40 reasonPhrase: reasonPhrase), |
| 41 this.stream = toByteStream(stream); |
36 } | 42 } |
OLD | NEW |