| 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 "package:crypto/crypto.dart"; | 5 import "package:crypto/crypto.dart"; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "package:path/path.dart"; | 7 import "package:path/path.dart"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 int get port => server.port; | 279 int get port => server.port; |
| 280 } | 280 } |
| 281 | 281 |
| 282 Future<ProxyServer> setupProxyServer({ipV6: false}) { | 282 Future<ProxyServer> setupProxyServer({ipV6: false}) { |
| 283 ProxyServer proxyServer = new ProxyServer(ipV6: ipV6); | 283 ProxyServer proxyServer = new ProxyServer(ipV6: ipV6); |
| 284 return proxyServer.start(); | 284 return proxyServer.start(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 testInvalidProxy() { | 287 testInvalidProxy() { |
| 288 HttpClient client = new HttpClient(); | 288 HttpClient client = new HttpClient(context: clientContext); |
| 289 | 289 |
| 290 client.findProxy = (Uri uri) => ""; | 290 client.findProxy = (Uri uri) => ""; |
| 291 client.getUrl(Uri.parse("http://www.google.com/test")) | 291 client.getUrl(Uri.parse("http://www.google.com/test")) |
| 292 .catchError((error) {}, test: (e) => e is HttpException); | 292 .catchError((error) {}, test: (e) => e is HttpException); |
| 293 | 293 |
| 294 client.findProxy = (Uri uri) => "XXX"; | 294 client.findProxy = (Uri uri) => "XXX"; |
| 295 client.getUrl(Uri.parse("http://www.google.com/test")) | 295 client.getUrl(Uri.parse("http://www.google.com/test")) |
| 296 .catchError((error) {}, test: (e) => e is HttpException); | 296 .catchError((error) {}, test: (e) => e is HttpException); |
| 297 | 297 |
| 298 client.findProxy = (Uri uri) => "PROXY www.google.com"; | 298 client.findProxy = (Uri uri) => "PROXY www.google.com"; |
| 299 client.getUrl(Uri.parse("http://www.google.com/test")) | 299 client.getUrl(Uri.parse("http://www.google.com/test")) |
| 300 .catchError((error) {}, test: (e) => e is HttpException); | 300 .catchError((error) {}, test: (e) => e is HttpException); |
| 301 | 301 |
| 302 client.findProxy = (Uri uri) => "PROXY www.google.com:http"; | 302 client.findProxy = (Uri uri) => "PROXY www.google.com:http"; |
| 303 client.getUrl(Uri.parse("http://www.google.com/test")) | 303 client.getUrl(Uri.parse("http://www.google.com/test")) |
| 304 .catchError((error) {}, test: (e) => e is HttpException); | 304 .catchError((error) {}, test: (e) => e is HttpException); |
| 305 } | 305 } |
| 306 | 306 |
| 307 int testDirectDoneCount = 0; | 307 int testDirectDoneCount = 0; |
| 308 void testDirectProxy() { | 308 void testDirectProxy() { |
| 309 setupServer(0).then((server) { | 309 setupServer(0).then((server) { |
| 310 HttpClient client = new HttpClient(); | 310 HttpClient client = new HttpClient(context: clientContext); |
| 311 List<String> proxy = | 311 List<String> proxy = |
| 312 ["DIRECT", " DIRECT ", "DIRECT ;", " DIRECT ; ", | 312 ["DIRECT", " DIRECT ", "DIRECT ;", " DIRECT ; ", |
| 313 ";DIRECT", " ; DIRECT ", ";;DIRECT;;"]; | 313 ";DIRECT", " ; DIRECT ", ";;DIRECT;;"]; |
| 314 | 314 |
| 315 client.findProxy = (Uri uri) { | 315 client.findProxy = (Uri uri) { |
| 316 int index = int.parse(uri.path.substring(1)); | 316 int index = int.parse(uri.path.substring(1)); |
| 317 return proxy[index]; | 317 return proxy[index]; |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 for (int i = 0; i < proxy.length; i++) { | 320 for (int i = 0; i < proxy.length; i++) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 409 |
| 410 | 410 |
| 411 int testProxyChainDoneCount = 0; | 411 int testProxyChainDoneCount = 0; |
| 412 void testProxyChain() { | 412 void testProxyChain() { |
| 413 // Setup two proxy servers having the first using the second as its proxy. | 413 // Setup two proxy servers having the first using the second as its proxy. |
| 414 setupProxyServer().then((proxyServer1) { | 414 setupProxyServer().then((proxyServer1) { |
| 415 setupProxyServer().then((proxyServer2) { | 415 setupProxyServer().then((proxyServer2) { |
| 416 proxyServer1.client.findProxy = (_) => "PROXY localhost:${proxyServer2.port}"; | 416 proxyServer1.client.findProxy = (_) => "PROXY localhost:${proxyServer2.port}"; |
| 417 | 417 |
| 418 setupServer(2, directRequestPaths: ["/4"]).then((server) { | 418 setupServer(2, directRequestPaths: ["/4"]).then((server) { |
| 419 HttpClient client = new HttpClient(); | 419 HttpClient client = new HttpClient(context: clientContext); |
| 420 | 420 |
| 421 List<String> proxy; | 421 List<String> proxy; |
| 422 if (Platform.operatingSystem == "windows") { | 422 if (Platform.operatingSystem == "windows") { |
| 423 proxy = | 423 proxy = |
| 424 ["PROXY localhost:${proxyServer1.port}", | 424 ["PROXY localhost:${proxyServer1.port}", |
| 425 "PROXY localhost:${proxyServer1.port}; PROXY hede.hule.hest:8080", | 425 "PROXY localhost:${proxyServer1.port}; PROXY hede.hule.hest:8080", |
| 426 "PROXY localhost:${proxyServer1.port}", | 426 "PROXY localhost:${proxyServer1.port}", |
| 427 "PROXY localhost:${proxyServer1.port}", | 427 "PROXY localhost:${proxyServer1.port}", |
| 428 "DIRECT", | 428 "DIRECT", |
| 429 "PROXY localhost:${proxyServer1.port}; DIRECT"]; | 429 "PROXY localhost:${proxyServer1.port}; DIRECT"]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 }); | 469 }); |
| 470 }); | 470 }); |
| 471 } | 471 } |
| 472 | 472 |
| 473 main() { | 473 main() { |
| 474 testInvalidProxy(); | 474 testInvalidProxy(); |
| 475 testDirectProxy(); | 475 testDirectProxy(); |
| 476 testProxy(); | 476 testProxy(); |
| 477 testProxyChain(); | 477 testProxyChain(); |
| 478 } | 478 } |
| OLD | NEW |