| 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_test; | 5 library request_test; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 request.body = "hello"; | 129 request.body = "hello"; |
| 130 expect(request.body, equals("hello")); | 130 expect(request.body, equals("hello")); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 test('changes when bodyBytes changes', () { | 133 test('changes when bodyBytes changes', () { |
| 134 var request = new http.Request('POST', dummyUrl); | 134 var request = new http.Request('POST', dummyUrl); |
| 135 request.bodyBytes = [104, 101, 108, 108, 111]; | 135 request.bodyBytes = [104, 101, 108, 108, 111]; |
| 136 expect(request.body, equals("hello")); | 136 expect(request.body, equals("hello")); |
| 137 }); | 137 }); |
| 138 | 138 |
| 139 // TODO(nweiz): test that both the getter and the setter respect #encoding | 139 test('is encoded according to the given encoding', () { |
| 140 // when issue 6284 is fixed. | 140 var request = new http.Request('POST', dummyUrl); |
| 141 request.encoding = LATIN1; |
| 142 request.body = "föøbãr"; |
| 143 expect(request.bodyBytes, equals([102, 246, 248, 98, 227, 114])); |
| 144 }); |
| 145 |
| 146 test('is decoded according to the given encoding', () { |
| 147 var request = new http.Request('POST', dummyUrl); |
| 148 request.encoding = LATIN1; |
| 149 request.bodyBytes = [102, 246, 248, 98, 227, 114]; |
| 150 expect(request.body, equals("föøbãr")); |
| 151 }); |
| 141 }); | 152 }); |
| 142 | 153 |
| 143 group('#bodyFields', () { | 154 group('#bodyFields', () { |
| 144 test("can't be read without setting the content-type", () { | 155 test("can't be read without setting the content-type", () { |
| 145 var request = new http.Request('POST', dummyUrl); | 156 var request = new http.Request('POST', dummyUrl); |
| 146 expect(() => request.bodyFields, throwsStateError); | 157 expect(() => request.bodyFields, throwsStateError); |
| 147 }); | 158 }); |
| 148 | 159 |
| 149 test("can't be read with the wrong content-type", () { | 160 test("can't be read with the wrong content-type", () { |
| 150 var request = new http.Request('POST', dummyUrl); | 161 var request = new http.Request('POST', dummyUrl); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 173 | 184 |
| 174 test('changes when body changes', () { | 185 test('changes when body changes', () { |
| 175 var request = new http.Request('POST', dummyUrl); | 186 var request = new http.Request('POST', dummyUrl); |
| 176 request.headers[HttpHeaders.CONTENT_TYPE] = | 187 request.headers[HttpHeaders.CONTENT_TYPE] = |
| 177 'application/x-www-form-urlencoded'; | 188 'application/x-www-form-urlencoded'; |
| 178 request.body = 'key%201=value&key+2=other%2bvalue'; | 189 request.body = 'key%201=value&key+2=other%2bvalue'; |
| 179 expect(request.bodyFields, | 190 expect(request.bodyFields, |
| 180 equals({'key 1': 'value', 'key 2': 'other+value'})); | 191 equals({'key 1': 'value', 'key 2': 'other+value'})); |
| 181 }); | 192 }); |
| 182 | 193 |
| 183 // TODO(nweiz): test that both the getter and the setter respect #encoding | 194 test('is encoded according to the given encoding', () { |
| 184 // when issue 6284 is fixed. | 195 var request = new http.Request('POST', dummyUrl); |
| 196 request.headers[HttpHeaders.CONTENT_TYPE] = |
| 197 'application/x-www-form-urlencoded'; |
| 198 request.encoding = LATIN1; |
| 199 request.bodyFields = {"föø": "bãr"}; |
| 200 expect(request.body, equals('f%F6%F8=b%E3r')); |
| 201 }); |
| 202 |
| 203 test('is decoded according to the given encoding', () { |
| 204 var request = new http.Request('POST', dummyUrl); |
| 205 request.headers[HttpHeaders.CONTENT_TYPE] = |
| 206 'application/x-www-form-urlencoded'; |
| 207 request.encoding = LATIN1; |
| 208 request.body = 'f%F6%F8=b%E3r'; |
| 209 expect(request.bodyFields, equals({"föø": "bãr"})); |
| 210 }); |
| 185 }); | 211 }); |
| 186 | 212 |
| 187 test('#followRedirects', () { | 213 test('#followRedirects', () { |
| 188 print("This test is known to be flaky, please ignore " | 214 print("This test is known to be flaky, please ignore " |
| 189 "(debug prints below added by sgjesse@)"); | 215 "(debug prints below added by sgjesse@)"); |
| 190 print("#followRedirects test starting server..."); | 216 print("#followRedirects test starting server..."); |
| 191 expect(startServer().then((_) { | 217 expect(startServer().then((_) { |
| 192 print("#followRedirects test server running"); | 218 print("#followRedirects test server running"); |
| 193 | 219 |
| 194 var request = new http.Request('POST', serverUrl.resolve('/redirect')) | 220 var request = new http.Request('POST', serverUrl.resolve('/redirect')) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 }); | 416 }); |
| 391 | 417 |
| 392 group('#toString()', () { | 418 group('#toString()', () { |
| 393 test('includes the method and URL', () { | 419 test('includes the method and URL', () { |
| 394 var request = new http.Request('POST', dummyUrl); | 420 var request = new http.Request('POST', dummyUrl); |
| 395 expect(request.toString(), 'POST $dummyUrl'); | 421 expect(request.toString(), 'POST $dummyUrl'); |
| 396 }); | 422 }); |
| 397 }); | 423 }); |
| 398 } | 424 } |
| 399 | 425 |
| OLD | NEW |