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 response; | 5 library response; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 List<int> bodyBytes, | 50 List<int> bodyBytes, |
51 int statusCode, | 51 int statusCode, |
52 {BaseRequest request, | 52 {BaseRequest request, |
53 Map<String, String> headers: const {}, | 53 Map<String, String> headers: const {}, |
54 bool isRedirect: false, | 54 bool isRedirect: false, |
55 bool persistentConnection: true, | 55 bool persistentConnection: true, |
56 String reasonPhrase}) | 56 String reasonPhrase}) |
57 : bodyBytes = toUint8List(bodyBytes), | 57 : bodyBytes = toUint8List(bodyBytes), |
58 super( | 58 super( |
59 statusCode, | 59 statusCode, |
60 bodyBytes.length, | 60 contentLength: bodyBytes.length, |
61 request: request, | 61 request: request, |
62 headers: headers, | 62 headers: headers, |
63 isRedirect: isRedirect, | 63 isRedirect: isRedirect, |
64 persistentConnection: persistentConnection, | 64 persistentConnection: persistentConnection, |
65 reasonPhrase: reasonPhrase); | 65 reasonPhrase: reasonPhrase); |
66 | 66 |
67 /// Creates a new HTTP response by waiting for the full body to become | 67 /// Creates a new HTTP response by waiting for the full body to become |
68 /// available from a [StreamedResponse]. | 68 /// available from a [StreamedResponse]. |
69 static Future<Response> fromStream(StreamedResponse response) { | 69 static Future<Response> fromStream(StreamedResponse response) { |
70 return response.stream.toBytes().then((body) { | 70 return response.stream.toBytes().then((body) { |
(...skipping 15 matching lines...) Expand all Loading... |
86 Encoding _encodingForHeaders(Map<String, String> headers) => | 86 Encoding _encodingForHeaders(Map<String, String> headers) => |
87 encodingForCharset(_contentTypeForHeaders(headers).charset); | 87 encodingForCharset(_contentTypeForHeaders(headers).charset); |
88 | 88 |
89 /// Returns the [ContentType] object for the given headers. Defaults to | 89 /// Returns the [ContentType] object for the given headers. Defaults to |
90 /// `application/octet-stream`. | 90 /// `application/octet-stream`. |
91 ContentType _contentTypeForHeaders(Map<String, String> headers) { | 91 ContentType _contentTypeForHeaders(Map<String, String> headers) { |
92 var contentType = headers[HttpHeaders.CONTENT_TYPE]; | 92 var contentType = headers[HttpHeaders.CONTENT_TYPE]; |
93 if (contentType != null) return ContentType.parse(contentType); | 93 if (contentType != null) return ContentType.parse(contentType); |
94 return new ContentType("application", "octet-stream"); | 94 return new ContentType("application", "octet-stream"); |
95 } | 95 } |
OLD | NEW |