| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library http.test.io.request_test; | |
| 6 | |
| 7 import 'package:http/http.dart' as http; | |
| 8 import 'package:unittest/unittest.dart'; | |
| 9 | |
| 10 import 'utils.dart'; | |
| 11 | |
| 12 void main() { | |
| 13 test('.send', () { | |
| 14 expect(startServer().then((_) { | |
| 15 | |
| 16 var request = new http.Request('POST', serverUrl); | |
| 17 request.body = "hello"; | |
| 18 request.headers['User-Agent'] = 'Dart'; | |
| 19 | |
| 20 expect(request.send().then((response) { | |
| 21 expect(response.statusCode, equals(200)); | |
| 22 return response.stream.bytesToString(); | |
| 23 }).whenComplete(stopServer), completion(parse(equals({ | |
| 24 'method': 'POST', | |
| 25 'path': '/', | |
| 26 'headers': { | |
| 27 'content-type': ['text/plain; charset=utf-8'], | |
| 28 'accept-encoding': ['gzip'], | |
| 29 'user-agent': ['Dart'], | |
| 30 'content-length': ['5'] | |
| 31 }, | |
| 32 'body': 'hello' | |
| 33 })))); | |
| 34 }), completes); | |
| 35 }); | |
| 36 | |
| 37 test('#followRedirects', () { | |
| 38 expect(startServer().then((_) { | |
| 39 var request = new http.Request('POST', serverUrl.resolve('/redirect')) | |
| 40 ..followRedirects = false; | |
| 41 var future = request.send().then((response) { | |
| 42 expect(response.statusCode, equals(302)); | |
| 43 }); | |
| 44 expect(future.catchError((_) {}).then((_) => stopServer()), completes); | |
| 45 expect(future, completes); | |
| 46 }), completes); | |
| 47 }); | |
| 48 | |
| 49 test('#maxRedirects', () { | |
| 50 expect(startServer().then((_) { | |
| 51 var request = new http.Request('POST', serverUrl.resolve('/loop?1')) | |
| 52 ..maxRedirects = 2; | |
| 53 var future = request.send().catchError((error) { | |
| 54 expect(error, isRedirectLimitExceededException); | |
| 55 expect(error.redirects.length, equals(2)); | |
| 56 }); | |
| 57 expect(future.catchError((_) {}).then((_) => stopServer()), completes); | |
| 58 expect(future, completes); | |
| 59 }), completes); | |
| 60 }); | |
| 61 } | |
| OLD | NEW |