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({bool clientAutoUncompress: true}) { | 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.autoCompress = true; |
17 server.listen((request) { | 18 server.listen((request) { |
18 request.response.add(data); | 19 request.response.add(data); |
19 request.response.close(); | 20 request.response.close(); |
20 }); | 21 }); |
21 var client = new HttpClient(); | 22 var client = new HttpClient(); |
22 client.autoUncompress = clientAutoUncompress; | 23 client.autoUncompress = clientAutoUncompress; |
23 client.get("127.0.0.1", server.port, "/") | 24 client.get("127.0.0.1", server.port, "/") |
24 .then((request) { | 25 .then((request) { |
25 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); | 26 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate"); |
26 return request.close(); | 27 return request.close(); |
(...skipping 21 matching lines...) Expand all Loading... |
48 var longBuffer = new Uint8List(1024 * 1024); | 49 var longBuffer = new Uint8List(1024 * 1024); |
49 for (int i = 0; i < longBuffer.length; i++) { | 50 for (int i = 0; i < longBuffer.length; i++) { |
50 longBuffer[i] = i & 0xFF; | 51 longBuffer[i] = i & 0xFF; |
51 } | 52 } |
52 test(longBuffer); | 53 test(longBuffer); |
53 } | 54 } |
54 | 55 |
55 void testAcceptEncodingHeader() { | 56 void testAcceptEncodingHeader() { |
56 void test(String encoding, bool valid) { | 57 void test(String encoding, bool valid) { |
57 HttpServer.bind("127.0.0.1", 0).then((server) { | 58 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 59 server.autoCompress = true; |
58 server.listen((request) { | 60 server.listen((request) { |
59 request.response.write("data"); | 61 request.response.write("data"); |
60 request.response.close(); | 62 request.response.close(); |
61 }); | 63 }); |
62 var client = new HttpClient(); | 64 var client = new HttpClient(); |
63 client.get("127.0.0.1", server.port, "/") | 65 client.get("127.0.0.1", server.port, "/") |
64 .then((request) { | 66 .then((request) { |
65 request.headers.set(HttpHeaders.ACCEPT_ENCODING, encoding); | 67 request.headers.set(HttpHeaders.ACCEPT_ENCODING, encoding); |
66 return request.close(); | 68 return request.close(); |
67 }) | 69 }) |
(...skipping 17 matching lines...) Expand all Loading... |
85 test('gzip , deflate', true); | 87 test('gzip , deflate', true); |
86 test('deflate,gzip', true); | 88 test('deflate,gzip', true); |
87 test('deflate, gzip', true); | 89 test('deflate, gzip', true); |
88 test('deflate ,gzip', true); | 90 test('deflate ,gzip', true); |
89 test('deflate , gzip', true); | 91 test('deflate , gzip', true); |
90 test('abc,deflate , gzip,def,,,ghi ,jkl', true); | 92 test('abc,deflate , gzip,def,,,ghi ,jkl', true); |
91 test('xgzip', false); | 93 test('xgzip', false); |
92 test('gzipx;', false); | 94 test('gzipx;', false); |
93 } | 95 } |
94 | 96 |
| 97 void testDisableCompressTest() { |
| 98 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 99 Expect.equals(false, server.autoCompress); |
| 100 server.listen((request) { |
| 101 Expect.equals('gzip', request.headers.value(HttpHeaders.ACCEPT_ENCODING)); |
| 102 request.response.write("data"); |
| 103 request.response.close(); |
| 104 }); |
| 105 var client = new HttpClient(); |
| 106 client.get("127.0.0.1", server.port, "/") |
| 107 .then((request) => request.close()) |
| 108 .then((response) { |
| 109 Expect.equals(null, |
| 110 response.headers.value(HttpHeaders.CONTENT_ENCODING)); |
| 111 response.listen( |
| 112 (_) {}, |
| 113 onDone: () { |
| 114 server.close(); |
| 115 client.close(); |
| 116 }); |
| 117 }); |
| 118 }); |
| 119 } |
| 120 |
95 void main() { | 121 void main() { |
96 testServerCompress(); | 122 testServerCompress(); |
97 testServerCompress(clientAutoUncompress: false); | 123 testServerCompress(clientAutoUncompress: false); |
98 testAcceptEncodingHeader(); | 124 testAcceptEncodingHeader(); |
| 125 testDisableCompressTest(); |
99 } | 126 } |
OLD | NEW |