| 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:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import 'dart:crypto'; | 7 import 'dart:crypto'; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 import "dart:uri"; | 9 import "dart:uri"; |
| 10 import 'dart:utf'; | 10 import 'dart:utf'; |
| 11 | 11 |
| 12 class Server { | 12 class Server { |
| 13 HttpServer server; | 13 HttpServer server; |
| 14 bool secure; | 14 bool secure; |
| 15 int proxyHops; | 15 int proxyHops; |
| 16 List<String> directRequestPaths; | 16 List<String> directRequestPaths; |
| 17 int requestCount = 0; | 17 int requestCount = 0; |
| 18 | 18 |
| 19 Server(this.proxyHops, this.directRequestPaths, this.secure); | 19 Server(this.proxyHops, this.directRequestPaths, this.secure); |
| 20 | 20 |
| 21 Future<Server> start() { | 21 Future<Server> start() { |
| 22 var x = new Completer(); | 22 var x = new Completer(); |
| 23 Future f = secure | 23 Future f = secure |
| 24 ? HttpServer.bindSecure( | 24 ? HttpServer.bindSecure( |
| 25 "localhost", 0, certificateName: 'localhost_cert') | 25 "localhost", 0, certificateName: 'localhost_cert') |
| 26 : HttpServer.bind("localhost"); | 26 : HttpServer.bind("localhost", 0); |
| 27 return f.then((s) { | 27 return f.then((s) { |
| 28 server = s; | 28 server = s; |
| 29 x.complete(this); | 29 x.complete(this); |
| 30 server.listen((request) { | 30 server.listen((request) { |
| 31 var response = request.response; | 31 var response = request.response; |
| 32 requestCount++; | 32 requestCount++; |
| 33 // Check whether a proxy or direct connection is expected. | 33 // Check whether a proxy or direct connection is expected. |
| 34 bool direct = directRequestPaths.fold( | 34 bool direct = directRequestPaths.fold( |
| 35 false, | 35 false, |
| 36 (prev, path) => prev ? prev : path == request.uri.path); | 36 (prev, path) => prev ? prev : path == request.uri.path); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 var response = request.response; | 90 var response = request.response; |
| 91 response.headers.set(HttpHeaders.PROXY_AUTHENTICATE, | 91 response.headers.set(HttpHeaders.PROXY_AUTHENTICATE, |
| 92 "Basic, realm=realm"); | 92 "Basic, realm=realm"); |
| 93 response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED; | 93 response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED; |
| 94 response.close(); | 94 response.close(); |
| 95 }); | 95 }); |
| 96 } | 96 } |
| 97 | 97 |
| 98 Future<ProxyServer> start() { | 98 Future<ProxyServer> start() { |
| 99 var x = new Completer(); | 99 var x = new Completer(); |
| 100 HttpServer.bind("localhost").then((s) { | 100 HttpServer.bind("localhost", 0).then((s) { |
| 101 server = s; | 101 server = s; |
| 102 x.complete(this); | 102 x.complete(this); |
| 103 server.listen((HttpRequest request) { | 103 server.listen((HttpRequest request) { |
| 104 requestCount++; | 104 requestCount++; |
| 105 if (username != null && password != null) { | 105 if (username != null && password != null) { |
| 106 if (request.headers[HttpHeaders.PROXY_AUTHORIZATION] == null) { | 106 if (request.headers[HttpHeaders.PROXY_AUTHORIZATION] == null) { |
| 107 authenticationRequired(request); | 107 authenticationRequired(request); |
| 108 return; | 108 return; |
| 109 } else { | 109 } else { |
| 110 Expect.equals( | 110 Expect.equals( |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 testDirectProxy(); | 638 testDirectProxy(); |
| 639 testProxy(); | 639 testProxy(); |
| 640 testProxyChain(); | 640 testProxyChain(); |
| 641 testProxyFromEnviroment(); | 641 testProxyFromEnviroment(); |
| 642 testProxyAuthenticate(); | 642 testProxyAuthenticate(); |
| 643 // This test is not normally run. It can be used for locally testing | 643 // This test is not normally run. It can be used for locally testing |
| 644 // with a real proxy server (e.g. Apache). | 644 // with a real proxy server (e.g. Apache). |
| 645 //testRealProxy(); | 645 //testRealProxy(); |
| 646 //testRealProxyAuth(); | 646 //testRealProxyAuth(); |
| 647 } | 647 } |
| OLD | NEW |