| 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 library http_server; | 5 library http_server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 .directoryPath | 64 .directoryPath |
| 65 .join(new Path('../../test.dart')) | 65 .join(new Path('../../test.dart')) |
| 66 .canonicalize() | 66 .canonicalize() |
| 67 .toNativePath(); | 67 .toNativePath(); |
| 68 var servers = new TestingServers(new Path(args['build-directory']), | 68 var servers = new TestingServers(new Path(args['build-directory']), |
| 69 args['csp']); | 69 args['csp']); |
| 70 var port = int.parse(args['port']); | 70 var port = int.parse(args['port']); |
| 71 var crossOriginPort = int.parse(args['crossOriginPort']); | 71 var crossOriginPort = int.parse(args['crossOriginPort']); |
| 72 servers.startServers(args['network'], | 72 servers.startServers(args['network'], |
| 73 port: port, | 73 port: port, |
| 74 crossOriginPort: crossOriginPort); | 74 crossOriginPort: crossOriginPort).then((_) { |
| 75 DebugLogger.info('Server listening on port ${servers.port}'); | 75 DebugLogger.info('Server listening on port ${servers.port}'); |
| 76 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); | 76 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); |
| 77 }); |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * Runs a set of servers that are initialized specifically for the needs of our | 82 * Runs a set of servers that are initialized specifically for the needs of our |
| 82 * test framework, such as dealing with package-root. | 83 * test framework, such as dealing with package-root. |
| 83 */ | 84 */ |
| 84 class TestingServers { | 85 class TestingServers { |
| 85 List _serverList = []; | 86 List _serverList = []; |
| 86 Path _buildDirectory = null; | 87 Path _buildDirectory = null; |
| 87 final bool useContentSecurityPolicy; | 88 final bool useContentSecurityPolicy; |
| 88 | 89 |
| 89 TestingServers(Path buildDirectory, this.useContentSecurityPolicy) { | 90 TestingServers(Path buildDirectory, this.useContentSecurityPolicy) { |
| 90 _buildDirectory = TestUtils.absolutePath(buildDirectory); | 91 _buildDirectory = TestUtils.absolutePath(buildDirectory); |
| 91 } | 92 } |
| 92 | 93 |
| 93 int get port => _serverList[0].port; | 94 int get port => _serverList[0].port; |
| 94 int get crossOriginPort => _serverList[1].port; | 95 int get crossOriginPort => _serverList[1].port; |
| 95 | 96 |
| 96 /** | 97 /** |
| 97 * [startServers] will start two Http servers. | 98 * [startServers] will start two Http servers. |
| 98 * The first server listens on [port] and sets | 99 * The first server listens on [port] and sets |
| 99 * "Access-Control-Allow-Origin: *" | 100 * "Access-Control-Allow-Origin: *" |
| 100 * The second server listens on [crossOriginPort] and sets | 101 * The second server listens on [crossOriginPort] and sets |
| 101 * "Access-Control-Allow-Origin: client:port1 | 102 * "Access-Control-Allow-Origin: client:port1 |
| 102 * "Access-Control-Allow-Credentials: true" | 103 * "Access-Control-Allow-Credentials: true" |
| 103 */ | 104 */ |
| 104 Future startServers(String host, {int port: 0, int crossOriginPort: 0}) { | 105 Future startServers(String host, {int port: 0, int crossOriginPort: 0}) { |
| 105 return _startHttpServer(host, port: port).then((_) { | 106 return _startHttpServer(host, port: port).then((server) { |
| 106 _startHttpServer(host, | 107 return _startHttpServer(host, |
| 107 port: crossOriginPort, | 108 port: crossOriginPort, |
| 108 allowedPort:_serverList[0].port); | 109 allowedPort:_serverList[0].port); |
| 109 }); | 110 }); |
| 110 } | 111 } |
| 111 | 112 |
| 112 String httpServerCommandline() { | 113 String httpServerCommandline() { |
| 113 var dart = TestUtils.dartTestExecutable.toNativePath(); | 114 var dart = TestUtils.dartTestExecutable.toNativePath(); |
| 114 var dartDir = TestUtils.dartDir(); | 115 var dartDir = TestUtils.dartDir(); |
| 115 var script = dartDir.join(new Path("tools/testing/dart/http_server.dart")); | 116 var script = dartDir.join(new Path("tools/testing/dart/http_server.dart")); |
| 116 var buildDirectory = _buildDirectory.toNativePath(); | 117 var buildDirectory = _buildDirectory.toNativePath(); |
| 117 var csp = useContentSecurityPolicy ? '--csp ' : ''; | 118 var csp = useContentSecurityPolicy ? '--csp ' : ''; |
| 118 | 119 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 class _Entry { | 332 class _Entry { |
| 332 final String name; | 333 final String name; |
| 333 final String displayName; | 334 final String displayName; |
| 334 | 335 |
| 335 _Entry(this.name, this.displayName); | 336 _Entry(this.name, this.displayName); |
| 336 | 337 |
| 337 int compareTo(_Entry other) { | 338 int compareTo(_Entry other) { |
| 338 return name.compareTo(other.name); | 339 return name.compareTo(other.name); |
| 339 } | 340 } |
| 340 } | 341 } |
| OLD | NEW |