| 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 client_test; | 5 library client_test; | 
| 6 | 6 | 
| 7 import 'dart:io'; | 7 import 'dart:io'; | 
| 8 import 'dart:uri'; | 8 import 'dart:uri'; | 
| 9 | 9 | 
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; | 
| 11 import 'package:http/http.dart' as http; | 11 import 'package:http/http.dart' as http; | 
| 12 import 'package:http/src/utils.dart'; | 12 import 'package:http/src/utils.dart'; | 
| 13 import 'utils.dart'; | 13 import 'utils.dart'; | 
| 14 | 14 | 
| 15 void main() { | 15 void main() { | 
| 16   setUp(startServer); |  | 
| 17   tearDown(stopServer); | 16   tearDown(stopServer); | 
| 18 | 17 | 
| 19   test('#send a StreamedRequest', () { | 18   test('#send a StreamedRequest', () { | 
| 20     var client = new http.Client(); | 19     expect(startServer().then((_) { | 
| 21     var request = new http.StreamedRequest("POST", serverUrl); | 20       var client = new http.Client(); | 
| 22     request.headers[HttpHeaders.CONTENT_TYPE] = | 21       var request = new http.StreamedRequest("POST", serverUrl); | 
| 23       'application/json; charset=utf-8'; | 22       request.headers[HttpHeaders.CONTENT_TYPE] = | 
|  | 23         'application/json; charset=utf-8'; | 
| 24 | 24 | 
| 25     expect(client.send(request).then((response) { | 25       expect(client.send(request).then((response) { | 
| 26       expect(response.request, equals(request)); | 26         expect(response.request, equals(request)); | 
| 27       expect(response.statusCode, equals(200)); | 27         expect(response.statusCode, equals(200)); | 
| 28       expect(response.headers['single'], equals('value')); | 28         expect(response.headers['single'], equals('value')); | 
| 29       // dart:io internally normalizes outgoing headers so that they never have | 29         // dart:io internally normalizes outgoing headers so that they never | 
| 30       // multiple headers with the same name, so there's no way to test whether | 30         // have multiple headers with the same name, so there's no way to test | 
| 31       // we handle that case correctly. | 31         // whether we handle that case correctly. | 
| 32 | 32 | 
| 33       return response.stream.bytesToString(); | 33         return response.stream.bytesToString(); | 
| 34     }).whenComplete(client.close), completion(parse(equals({ | 34       }).whenComplete(client.close), completion(parse(equals({ | 
| 35       'method': 'POST', | 35         'method': 'POST', | 
| 36       'path': '/', | 36         'path': '/', | 
| 37       'headers': { | 37         'headers': { | 
| 38         'content-type': ['application/json; charset=utf-8'], | 38           'content-type': ['application/json; charset=utf-8'], | 
| 39         'transfer-encoding': ['chunked'] | 39           'transfer-encoding': ['chunked'] | 
| 40       }, | 40         }, | 
| 41       'body': '{"hello": "world"}' | 41         'body': '{"hello": "world"}' | 
| 42     })))); | 42       })))); | 
| 43 | 43 | 
| 44     request.sink.add('{"hello": "world"}'.charCodes); | 44       request.sink.add('{"hello": "world"}'.charCodes); | 
| 45     request.sink.close(); | 45       request.sink.close(); | 
|  | 46     }), completes); | 
| 46   }); | 47   }); | 
| 47 | 48 | 
| 48   test('#send with an invalid URL', () { | 49   test('#send with an invalid URL', () { | 
| 49     var client = new http.Client(); | 50     expect(startServer().then((_) { | 
| 50     var url = Uri.parse('http://http.invalid'); | 51       var client = new http.Client(); | 
| 51     var request = new http.StreamedRequest("POST", url); | 52       var url = Uri.parse('http://http.invalid'); | 
| 52     request.headers[HttpHeaders.CONTENT_TYPE] = | 53       var request = new http.StreamedRequest("POST", url); | 
| 53         'application/json; charset=utf-8'; | 54       request.headers[HttpHeaders.CONTENT_TYPE] = | 
|  | 55           'application/json; charset=utf-8'; | 
| 54 | 56 | 
| 55     expect(client.send(request), throwsSocketIOException); | 57       expect(client.send(request), throwsSocketIOException); | 
| 56 | 58 | 
| 57     request.sink.add('{"hello": "world"}'.charCodes); | 59       request.sink.add('{"hello": "world"}'.charCodes); | 
| 58     request.sink.close(); | 60       request.sink.close(); | 
|  | 61     }), completes); | 
| 59   }); | 62   }); | 
| 60 } | 63 } | 
| OLD | NEW | 
|---|