| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 request; | 5 library request; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:scalarlist'; | 9 import 'dart:scalarlist'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 /// | 42 /// |
| 43 /// If the `charset` parameter's value is not a known [Encoding], reading this | 43 /// If the `charset` parameter's value is not a known [Encoding], reading this |
| 44 /// will throw a [FormatException]. | 44 /// will throw a [FormatException]. |
| 45 /// | 45 /// |
| 46 /// If the request has a `Content-Type` header, setting this will set the | 46 /// If the request has a `Content-Type` header, setting this will set the |
| 47 /// charset parameter on that header. | 47 /// charset parameter on that header. |
| 48 Encoding get encoding { | 48 Encoding get encoding { |
| 49 if (_contentType == null || _contentType.charset == null) { | 49 if (_contentType == null || _contentType.charset == null) { |
| 50 return _defaultEncoding; | 50 return _defaultEncoding; |
| 51 } | 51 } |
| 52 return requiredEncodingForCharset(_contentType.charset); | 52 var encoding = Encoding.fromName(_contentType.charset); |
| 53 if (encoding == null) { |
| 54 throw new FormatException( |
| 55 'Unsupported encoding "${_contentType.charset}".'); |
| 56 } |
| 57 return encoding; |
| 53 } | 58 } |
| 54 | 59 |
| 55 set encoding(Encoding value) { | 60 set encoding(Encoding value) { |
| 56 _checkFinalized(); | 61 _checkFinalized(); |
| 57 _defaultEncoding = value; | 62 _defaultEncoding = value; |
| 58 var contentType = _contentType; | 63 var contentType = _contentType; |
| 59 if (contentType != null) { | 64 if (contentType != null) { |
| 60 contentType = new ContentType(contentType.primaryType, | 65 contentType = new ContentType(contentType.primaryType, |
| 61 contentType.subType, | 66 contentType.subType, |
| 62 charset: value.name, | 67 charset: value.name, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 set _contentType(ContentType value) { | 165 set _contentType(ContentType value) { |
| 161 headers[HttpHeaders.CONTENT_TYPE] = value.toString(); | 166 headers[HttpHeaders.CONTENT_TYPE] = value.toString(); |
| 162 } | 167 } |
| 163 | 168 |
| 164 /// Throw an error if this request has been finalized. | 169 /// Throw an error if this request has been finalized. |
| 165 void _checkFinalized() { | 170 void _checkFinalized() { |
| 166 if (!finalized) return; | 171 if (!finalized) return; |
| 167 throw new StateError("Can't modify a finalized Request."); | 172 throw new StateError("Can't modify a finalized Request."); |
| 168 } | 173 } |
| 169 } | 174 } |
| OLD | NEW |