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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:uri"; | 7 import "dart:uri"; |
8 | 8 |
9 class Server { | 9 class Server { |
10 HttpServer server; | 10 HttpServer server; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 var body = new StringBuffer(); | 43 var body = new StringBuffer(); |
44 request.listen( | 44 request.listen( |
45 (data) { | 45 (data) { |
46 body.add(new String.fromCharCodes(data)); | 46 body.add(new String.fromCharCodes(data)); |
47 }, | 47 }, |
48 onDone: () { | 48 onDone: () { |
49 String path = request.uri.path.substring(1); | 49 String path = request.uri.path.substring(1); |
50 String content = "$path$path$path"; | 50 String content = "$path$path$path"; |
51 Expect.equals(content, body.toString()); | 51 Expect.equals(content, body.toString()); |
52 response.addString(request.uri.path); | 52 response.write(request.uri.path); |
53 response.close(); | 53 response.close(); |
54 }); | 54 }); |
55 }); | 55 }); |
56 return x.future; | 56 return x.future; |
57 }); | 57 }); |
58 } | 58 } |
59 | 59 |
60 void shutdown() { | 60 void shutdown() { |
61 server.close(); | 61 server.close(); |
62 } | 62 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 client.findProxy = (Uri uri) { | 158 client.findProxy = (Uri uri) { |
159 int index = int.parse(uri.path.substring(1)); | 159 int index = int.parse(uri.path.substring(1)); |
160 return proxy[index]; | 160 return proxy[index]; |
161 }; | 161 }; |
162 | 162 |
163 for (int i = 0; i < proxy.length; i++) { | 163 for (int i = 0; i < proxy.length; i++) { |
164 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) | 164 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) |
165 .then((HttpClientRequest clientRequest) { | 165 .then((HttpClientRequest clientRequest) { |
166 String content = "$i$i$i"; | 166 String content = "$i$i$i"; |
167 clientRequest.contentLength = content.length; | 167 clientRequest.contentLength = content.length; |
168 clientRequest.addString(content); | 168 clientRequest.write(content); |
169 return clientRequest.close(); | 169 return clientRequest.close(); |
170 }) | 170 }) |
171 .then((HttpClientResponse response) { | 171 .then((HttpClientResponse response) { |
172 response.listen((_) {}, onDone: () { | 172 response.listen((_) {}, onDone: () { |
173 testDirectDoneCount++; | 173 testDirectDoneCount++; |
174 if (testDirectDoneCount == proxy.length) { | 174 if (testDirectDoneCount == proxy.length) { |
175 Expect.equals(proxy.length, server.requestCount); | 175 Expect.equals(proxy.length, server.requestCount); |
176 server.shutdown(); | 176 server.shutdown(); |
177 client.close(); | 177 client.close(); |
178 } | 178 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 for (int i = 0; i < proxy.length; i++) { | 218 for (int i = 0; i < proxy.length; i++) { |
219 test(bool secure) { | 219 test(bool secure) { |
220 String url = secure | 220 String url = secure |
221 ? "https://localhost:${secureServer.port}/$i" | 221 ? "https://localhost:${secureServer.port}/$i" |
222 : "http://127.0.0.1:${server.port}/$i"; | 222 : "http://127.0.0.1:${server.port}/$i"; |
223 | 223 |
224 client.postUrl(Uri.parse(url)) | 224 client.postUrl(Uri.parse(url)) |
225 .then((HttpClientRequest clientRequest) { | 225 .then((HttpClientRequest clientRequest) { |
226 String content = "$i$i$i"; | 226 String content = "$i$i$i"; |
227 clientRequest.addString(content); | 227 clientRequest.write(content); |
228 return clientRequest.close(); | 228 return clientRequest.close(); |
229 }) | 229 }) |
230 .then((HttpClientResponse response) { | 230 .then((HttpClientResponse response) { |
231 response.listen((_) {}, onDone: () { | 231 response.listen((_) {}, onDone: () { |
232 testProxyDoneCount++; | 232 testProxyDoneCount++; |
233 if (testProxyDoneCount == proxy.length * 2) { | 233 if (testProxyDoneCount == proxy.length * 2) { |
234 Expect.equals(proxy.length, server.requestCount); | 234 Expect.equals(proxy.length, server.requestCount); |
235 proxyServer.shutdown(); | 235 proxyServer.shutdown(); |
236 server.shutdown(); | 236 server.shutdown(); |
237 secureServer.shutdown(); | 237 secureServer.shutdown(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // Pick the proxy configuration based on the request path. | 283 // Pick the proxy configuration based on the request path. |
284 int index = int.parse(uri.path.substring(1)); | 284 int index = int.parse(uri.path.substring(1)); |
285 return proxy[index]; | 285 return proxy[index]; |
286 }; | 286 }; |
287 | 287 |
288 for (int i = 0; i < proxy.length; i++) { | 288 for (int i = 0; i < proxy.length; i++) { |
289 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) | 289 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) |
290 .then((HttpClientRequest clientRequest) { | 290 .then((HttpClientRequest clientRequest) { |
291 String content = "$i$i$i"; | 291 String content = "$i$i$i"; |
292 clientRequest.contentLength = content.length; | 292 clientRequest.contentLength = content.length; |
293 clientRequest.addString(content); | 293 clientRequest.write(content); |
294 return clientRequest.close(); | 294 return clientRequest.close(); |
295 }) | 295 }) |
296 .then((HttpClientResponse response) { | 296 .then((HttpClientResponse response) { |
297 response.listen((_) {}, onDone: () { | 297 response.listen((_) {}, onDone: () { |
298 testProxyChainDoneCount++; | 298 testProxyChainDoneCount++; |
299 if (testProxyChainDoneCount == proxy.length) { | 299 if (testProxyChainDoneCount == proxy.length) { |
300 Expect.equals(proxy.length, server.requestCount); | 300 Expect.equals(proxy.length, server.requestCount); |
301 proxyServer1.shutdown(); | 301 proxyServer1.shutdown(); |
302 proxyServer2.shutdown(); | 302 proxyServer2.shutdown(); |
303 server.shutdown(); | 303 server.shutdown(); |
(...skipping 22 matching lines...) Expand all Loading... |
326 // Pick the proxy configuration based on the request path. | 326 // Pick the proxy configuration based on the request path. |
327 int index = int.parse(uri.path.substring(1)); | 327 int index = int.parse(uri.path.substring(1)); |
328 return proxy[index]; | 328 return proxy[index]; |
329 }; | 329 }; |
330 | 330 |
331 for (int i = 0; i < proxy.length; i++) { | 331 for (int i = 0; i < proxy.length; i++) { |
332 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) | 332 client.getUrl(Uri.parse("http://127.0.0.1:${server.port}/$i")) |
333 .then((HttpClientRequest clientRequest) { | 333 .then((HttpClientRequest clientRequest) { |
334 String content = "$i$i$i"; | 334 String content = "$i$i$i"; |
335 clientRequest.contentLength = content.length; | 335 clientRequest.contentLength = content.length; |
336 clientRequest.addString(content); | 336 clientRequest.write(content); |
337 return clientRequest.close(); | 337 return clientRequest.close(); |
338 }) | 338 }) |
339 .then((HttpClientResponse response) { | 339 .then((HttpClientResponse response) { |
340 response.listen((_) {}, onDone: () { | 340 response.listen((_) {}, onDone: () { |
341 testRealProxyDoneCount++; | 341 testRealProxyDoneCount++; |
342 if (testRealProxyDoneCount == proxy.length) { | 342 if (testRealProxyDoneCount == proxy.length) { |
343 Expect.equals(proxy.length, server.requestCount); | 343 Expect.equals(proxy.length, server.requestCount); |
344 server.shutdown(); | 344 server.shutdown(); |
345 client.close(); | 345 client.close(); |
346 } | 346 } |
(...skipping 13 matching lines...) Expand all Loading... |
360 main() { | 360 main() { |
361 InitializeSSL(); | 361 InitializeSSL(); |
362 testInvalidProxy(); | 362 testInvalidProxy(); |
363 testDirectProxy(); | 363 testDirectProxy(); |
364 testProxy(); | 364 testProxy(); |
365 testProxyChain(); | 365 testProxyChain(); |
366 // This test is not normally run. It can be used for locally testing | 366 // This test is not normally run. It can be used for locally testing |
367 // with a real proxy server (e.g. Apache). | 367 // with a real proxy server (e.g. Apache). |
368 //testRealProxy(); | 368 //testRealProxy(); |
369 } | 369 } |
OLD | NEW |