OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 shelf.message; | 5 library shelf.message; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:http_parser/http_parser.dart'; | 10 import 'package:http_parser/http_parser.dart'; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 /// | 82 /// |
83 /// If [headers] doesn't have a Content-Type header, this will be `null`. | 83 /// If [headers] doesn't have a Content-Type header, this will be `null`. |
84 String get mimeType { | 84 String get mimeType { |
85 var contentType = _contentType; | 85 var contentType = _contentType; |
86 if (contentType == null) return null; | 86 if (contentType == null) return null; |
87 return contentType.mimeType; | 87 return contentType.mimeType; |
88 } | 88 } |
89 | 89 |
90 /// The encoding of the message body. | 90 /// The encoding of the message body. |
91 /// | 91 /// |
92 /// This is parsed from the "charset" paramater of the Content-Type header in | 92 /// This is parsed from the "charset" parameter of the Content-Type header in |
93 /// [headers]. | 93 /// [headers]. |
94 /// | 94 /// |
95 /// If [headers] doesn't have a Content-Type header or it specifies an | 95 /// If [headers] doesn't have a Content-Type header or it specifies an |
96 /// encoding that [dart:convert] doesn't support, this will be `null`. | 96 /// encoding that [dart:convert] doesn't support, this will be `null`. |
97 Encoding get encoding { | 97 Encoding get encoding { |
98 var contentType = _contentType; | 98 var contentType = _contentType; |
99 if (contentType == null) return null; | 99 if (contentType == null) return null; |
100 if (!contentType.parameters.containsKey('charset')) return null; | 100 if (!contentType.parameters.containsKey('charset')) return null; |
101 return Encoding.getByName(contentType.parameters['charset']); | 101 return Encoding.getByName(contentType.parameters['charset']); |
102 } | 102 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 if (encoding == null) return headers; | 165 if (encoding == null) return headers; |
166 if (headers['content-type'] == null) { | 166 if (headers['content-type'] == null) { |
167 return addHeader(headers, 'content-type', | 167 return addHeader(headers, 'content-type', |
168 'application/octet-stream; charset=${encoding.name}'); | 168 'application/octet-stream; charset=${encoding.name}'); |
169 } | 169 } |
170 | 170 |
171 var contentType = new MediaType.parse(headers['content-type']).change( | 171 var contentType = new MediaType.parse(headers['content-type']).change( |
172 parameters: {'charset': encoding.name}); | 172 parameters: {'charset': encoding.name}); |
173 return addHeader(headers, 'content-type', contentType.toString()); | 173 return addHeader(headers, 'content-type', contentType.toString()); |
174 } | 174 } |
OLD | NEW |