| 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:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 /// `application/x-www-form-urlencoded`. | 114 /// `application/x-www-form-urlencoded`. |
| 115 /// | 115 /// |
| 116 /// This map should only be set, not modified in place. | 116 /// This map should only be set, not modified in place. |
| 117 Map<String, String> get bodyFields { | 117 Map<String, String> get bodyFields { |
| 118 if (_contentType == null || | 118 if (_contentType == null || |
| 119 _contentType.value != "application/x-www-form-urlencoded") { | 119 _contentType.value != "application/x-www-form-urlencoded") { |
| 120 throw new StateError('Cannot access the body fields of a Request without ' | 120 throw new StateError('Cannot access the body fields of a Request without ' |
| 121 'content-type "application/x-www-form-urlencoded".'); | 121 'content-type "application/x-www-form-urlencoded".'); |
| 122 } | 122 } |
| 123 | 123 |
| 124 return queryToMap(body); | 124 return queryToMap(body, encoding: encoding); |
| 125 } | 125 } |
| 126 | 126 |
| 127 set bodyFields(Map<String, String> fields) { | 127 set bodyFields(Map<String, String> fields) { |
| 128 if (_contentType == null) { | 128 if (_contentType == null) { |
| 129 _contentType = new ContentType("application", "x-www-form-urlencoded"); | 129 _contentType = new ContentType("application", "x-www-form-urlencoded"); |
| 130 } else if (_contentType.value != "application/x-www-form-urlencoded") { | 130 } else if (_contentType.value != "application/x-www-form-urlencoded") { |
| 131 throw new StateError('Cannot set the body fields of a Request with ' | 131 throw new StateError('Cannot set the body fields of a Request with ' |
| 132 'content-type "${_contentType.value}".'); | 132 'content-type "${_contentType.value}".'); |
| 133 } | 133 } |
| 134 | 134 |
| 135 this.body = mapToQuery(fields); | 135 this.body = mapToQuery(fields, encoding: encoding); |
| 136 } | 136 } |
| 137 | 137 |
| 138 /// Creates a new HTTP request. | 138 /// Creates a new HTTP request. |
| 139 Request(String method, Uri url) | 139 Request(String method, Uri url) |
| 140 : super(method, url), | 140 : super(method, url), |
| 141 _defaultEncoding = UTF8, | 141 _defaultEncoding = UTF8, |
| 142 _bodyBytes = new Uint8List(0); | 142 _bodyBytes = new Uint8List(0); |
| 143 | 143 |
| 144 /// Freezes all mutable fields and returns a single-subscription [ByteStream] | 144 /// Freezes all mutable fields and returns a single-subscription [ByteStream] |
| 145 /// containing the request body. | 145 /// containing the request body. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 159 set _contentType(ContentType value) { | 159 set _contentType(ContentType value) { |
| 160 headers[HttpHeaders.CONTENT_TYPE] = value.toString(); | 160 headers[HttpHeaders.CONTENT_TYPE] = value.toString(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /// Throw an error if this request has been finalized. | 163 /// Throw an error if this request has been finalized. |
| 164 void _checkFinalized() { | 164 void _checkFinalized() { |
| 165 if (!finalized) return; | 165 if (!finalized) return; |
| 166 throw new StateError("Can't modify a finalized Request."); | 166 throw new StateError("Can't modify a finalized Request."); |
| 167 } | 167 } |
| 168 } | 168 } |
| OLD | NEW |