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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
11 import 'dart:io'; | 11 import 'dart:io'; |
12 import 'dart:typed_data'; | 12 import 'dart:typed_data'; |
13 | 13 |
14 void testServerCompress() { | 14 void testServerCompress({bool clientAutoUncompress: true}) { |
15 void test(List<int> data) { | 15 void test(List<int> data) { |
16 HttpServer.bind("127.0.0.1", 0).then((server) { | 16 HttpServer.bind("127.0.0.1", 0).then((server) { |
17 server.listen((request) { | 17 server.listen((request) { |
18 request.response.add(data); | 18 request.response.add(data); |
19 request.response.close(); | 19 request.response.close(); |
20 }); | 20 }); |
21 var client = new HttpClient(); | 21 var client = new HttpClient(); |
| 22 client.autoUncompress = clientAutoUncompress; |
22 client.get("127.0.0.1", server.port, "/") | 23 client.get("127.0.0.1", server.port, "/") |
23 .then((request) { | 24 .then((request) { |
24 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); | 25 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); |
25 return request.close(); | 26 return request.close(); |
26 }) | 27 }) |
27 .then((response) { | 28 .then((response) { |
28 Expect.equals("gzip", | 29 Expect.equals("gzip", |
29 response.headers.value(HttpHeaders.CONTENT_ENCODING)); | 30 response.headers.value(HttpHeaders.CONTENT_ENCODING)); |
30 response | 31 response |
31 .fold([], (list, b) { | 32 .fold([], (list, b) { |
32 list.addAll(b); | 33 list.addAll(b); |
33 return list; | 34 return list; |
34 }).then((list) { | 35 }).then((list) { |
35 Expect.listEquals(data, list); | 36 if (clientAutoUncompress) { |
| 37 Expect.listEquals(data, list); |
| 38 } else { |
| 39 Expect.listEquals(data, GZIP.decode(list)); |
| 40 } |
36 server.close(); | 41 server.close(); |
37 client.close(); | 42 client.close(); |
38 }); | 43 }); |
39 }); | 44 }); |
40 }); | 45 }); |
41 } | 46 } |
42 test("My raw server provided data".codeUnits); | 47 test("My raw server provided data".codeUnits); |
43 var longBuffer = new Uint8List(1024 * 1024); | 48 var longBuffer = new Uint8List(1024 * 1024); |
44 for (int i = 0; i < longBuffer.length; i++) { | 49 for (int i = 0; i < longBuffer.length; i++) { |
45 longBuffer[i] = i & 0xFF; | 50 longBuffer[i] = i & 0xFF; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 test('deflate, gzip', true); | 87 test('deflate, gzip', true); |
83 test('deflate ,gzip', true); | 88 test('deflate ,gzip', true); |
84 test('deflate , gzip', true); | 89 test('deflate , gzip', true); |
85 test('abc,deflate , gzip,def,,,ghi ,jkl', true); | 90 test('abc,deflate , gzip,def,,,ghi ,jkl', true); |
86 test('xgzip', false); | 91 test('xgzip', false); |
87 test('gzipx;', false); | 92 test('gzipx;', false); |
88 } | 93 } |
89 | 94 |
90 void main() { | 95 void main() { |
91 testServerCompress(); | 96 testServerCompress(); |
| 97 testServerCompress(clientAutoUncompress: false); |
92 testAcceptEncodingHeader(); | 98 testAcceptEncodingHeader(); |
93 } | 99 } |
OLD | NEW |