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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 .then((HttpClientRequest clientRequest) { | 225 .then((HttpClientRequest clientRequest) { |
226 String content = "$i$i$i"; | 226 String content = "$i$i$i"; |
227 clientRequest.write(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 Expect.equals(proxy.length, secureServer.requestCount); |
235 proxyServer.shutdown(); | 236 proxyServer.shutdown(); |
236 server.shutdown(); | 237 server.shutdown(); |
237 secureServer.shutdown(); | 238 secureServer.shutdown(); |
238 client.close(); | 239 client.close(); |
239 } | 240 } |
240 }); | 241 }); |
241 }); | 242 }); |
242 } | 243 } |
243 | 244 |
244 test(false); | 245 test(false); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 client.close(); | 305 client.close(); |
305 } | 306 } |
306 }); | 307 }); |
307 }); | 308 }); |
308 } | 309 } |
309 }); | 310 }); |
310 }); | 311 }); |
311 }); | 312 }); |
312 } | 313 } |
313 | 314 |
| 315 int testProxyFromEnviromentDoneCount = 0; |
| 316 void testProxyFromEnviroment() { |
| 317 setupProxyServer().then((proxyServer) { |
| 318 setupServer(1).then((server) { |
| 319 setupServer(1, secure: true).then((secureServer) { |
| 320 HttpClient client = new HttpClient(); |
| 321 |
| 322 client.findProxy = (Uri uri) { |
| 323 return HttpClient.findProxyFromEnvironment( |
| 324 uri, |
| 325 environment: {"http_proxy": "localhost:${proxyServer.port}", |
| 326 "https_proxy": "localhost:${proxyServer.port}"}); |
| 327 }; |
| 328 |
| 329 const int loopCount = 5; |
| 330 for (int i = 0; i < loopCount; i++) { |
| 331 test(bool secure) { |
| 332 String url = secure |
| 333 ? "https://localhost:${secureServer.port}/$i" |
| 334 : "http://127.0.0.1:${server.port}/$i"; |
| 335 |
| 336 client.postUrl(Uri.parse(url)) |
| 337 .then((HttpClientRequest clientRequest) { |
| 338 String content = "$i$i$i"; |
| 339 clientRequest.write(content); |
| 340 return clientRequest.close(); |
| 341 }) |
| 342 .then((HttpClientResponse response) { |
| 343 response.listen((_) {}, onDone: () { |
| 344 testProxyFromEnviromentDoneCount++; |
| 345 if (testProxyFromEnviromentDoneCount == loopCount * 2) { |
| 346 Expect.equals(loopCount, server.requestCount); |
| 347 Expect.equals(loopCount, secureServer.requestCount); |
| 348 proxyServer.shutdown(); |
| 349 server.shutdown(); |
| 350 secureServer.shutdown(); |
| 351 client.close(); |
| 352 } |
| 353 }); |
| 354 }); |
| 355 } |
| 356 |
| 357 test(false); |
| 358 test(true); |
| 359 } |
| 360 }); |
| 361 }); |
| 362 }); |
| 363 } |
| 364 |
314 int testRealProxyDoneCount = 0; | 365 int testRealProxyDoneCount = 0; |
315 void testRealProxy() { | 366 void testRealProxy() { |
316 setupServer(1).then((server) { | 367 setupServer(1).then((server) { |
317 HttpClient client = new HttpClient(); | 368 HttpClient client = new HttpClient(); |
318 | 369 |
319 List<String> proxy = | 370 List<String> proxy = |
320 ["PROXY localhost:8080", | 371 ["PROXY localhost:8080", |
321 "PROXY localhost:8080; PROXY hede.hule.hest:8080", | 372 "PROXY localhost:8080; PROXY hede.hule.hest:8080", |
322 "PROXY hede.hule.hest:8080; PROXY localhost:8080", | 373 "PROXY hede.hule.hest:8080; PROXY localhost:8080", |
323 "PROXY localhost:8080; DIRECT"]; | 374 "PROXY localhost:8080; DIRECT"]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), | 407 SecureSocket.initialize(database: testPkcertDatabase.toNativePath(), |
357 password: 'dartdart'); | 408 password: 'dartdart'); |
358 } | 409 } |
359 | 410 |
360 main() { | 411 main() { |
361 InitializeSSL(); | 412 InitializeSSL(); |
362 testInvalidProxy(); | 413 testInvalidProxy(); |
363 testDirectProxy(); | 414 testDirectProxy(); |
364 testProxy(); | 415 testProxy(); |
365 testProxyChain(); | 416 testProxyChain(); |
| 417 testProxyFromEnviroment(); |
366 // This test is not normally run. It can be used for locally testing | 418 // This test is not normally run. It can be used for locally testing |
367 // with a real proxy server (e.g. Apache). | 419 // with a real proxy server (e.g. Apache). |
368 //testRealProxy(); | 420 //testRealProxy(); |
369 } | 421 } |
OLD | NEW |