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.streamed_request_test; | |
6 | |
7 import 'dart:convert'; | |
8 | |
9 import 'package:http/http.dart' as http; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 import 'utils.dart'; | |
13 | |
14 void main() { | |
15 group('contentLength', () { | |
16 test('controls the Content-Length header', () { | |
17 return startServer().then((_) { | |
18 var request = new http.StreamedRequest('POST', serverUrl); | |
19 request.contentLength = 10; | |
20 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
21 request.sink.close(); | |
22 | |
23 return request.send(); | |
24 }).then((response) { | |
25 expect(UTF8.decodeStream(response.stream), | |
26 completion(parse(containsPair('headers', | |
27 containsPair('content-length', ['10']))))); | |
28 }).whenComplete(stopServer); | |
29 }); | |
30 | |
31 test('defaults to sending no Content-Length', () { | |
32 return startServer().then((_) { | |
33 var request = new http.StreamedRequest('POST', serverUrl); | |
34 request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); | |
35 request.sink.close(); | |
36 | |
37 return request.send(); | |
38 }).then((response) { | |
39 expect(UTF8.decodeStream(response.stream), | |
40 completion(parse(containsPair('headers', | |
41 isNot(contains('content-length')))))); | |
42 }).whenComplete(stopServer); | |
43 }); | |
44 }); | |
45 | |
46 // Regression test. | |
47 test('.send() with a response with no content length', () { | |
48 return startServer().then((_) { | |
49 var request = new http.StreamedRequest( | |
50 'GET', serverUrl.resolve('/no-content-length')); | |
51 request.sink.close(); | |
52 return request.send(); | |
53 }).then((response) { | |
54 expect(UTF8.decodeStream(response.stream), completion(equals('body'))); | |
55 }).whenComplete(stopServer); | |
56 }); | |
57 | |
58 } | |
OLD | NEW |