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'; | |
10 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
11 | 10 |
| 11 import 'package:http_parser/http_parser.dart'; |
| 12 |
12 import 'base_request.dart'; | 13 import 'base_request.dart'; |
13 import 'base_response.dart'; | 14 import 'base_response.dart'; |
14 import 'streamed_response.dart'; | 15 import 'streamed_response.dart'; |
15 import 'utils.dart'; | 16 import 'utils.dart'; |
16 | 17 |
17 /// An HTTP response where the entire response body is known in advance. | 18 /// An HTTP response where the entire response body is known in advance. |
18 class Response extends BaseResponse { | 19 class Response extends BaseResponse { |
19 /// The bytes comprising the body of this response. | 20 /// The bytes comprising the body of this response. |
20 final Uint8List bodyBytes; | 21 final Uint8List bodyBytes; |
21 | 22 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 persistentConnection: response.persistentConnection, | 78 persistentConnection: response.persistentConnection, |
78 reasonPhrase: response.reasonPhrase); | 79 reasonPhrase: response.reasonPhrase); |
79 }); | 80 }); |
80 } | 81 } |
81 } | 82 } |
82 | 83 |
83 /// Returns the encoding to use for a response with the given headers. This | 84 /// Returns the encoding to use for a response with the given headers. This |
84 /// defaults to [LATIN1] if the headers don't specify a charset or | 85 /// defaults to [LATIN1] if the headers don't specify a charset or |
85 /// if that charset is unknown. | 86 /// if that charset is unknown. |
86 Encoding _encodingForHeaders(Map<String, String> headers) => | 87 Encoding _encodingForHeaders(Map<String, String> headers) => |
87 encodingForCharset(_contentTypeForHeaders(headers).charset); | 88 encodingForCharset(_contentTypeForHeaders(headers).parameters['charset']); |
88 | 89 |
89 /// Returns the [ContentType] object for the given headers. Defaults to | 90 /// Returns the [MediaType] object for the given headers's content-type. |
90 /// `application/octet-stream`. | 91 /// |
91 ContentType _contentTypeForHeaders(Map<String, String> headers) { | 92 /// Defaults to `application/octet-stream`. |
92 var contentType = headers[HttpHeaders.CONTENT_TYPE]; | 93 MediaType _contentTypeForHeaders(Map<String, String> headers) { |
93 if (contentType != null) return ContentType.parse(contentType); | 94 var contentType = headers['content-type']; |
94 return new ContentType("application", "octet-stream"); | 95 if (contentType != null) return new MediaType.parse(contentType); |
| 96 return new MediaType("application", "octet-stream"); |
95 } | 97 } |
OLD | NEW |