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; |
| 6 |
5 import 'dart:async'; | 7 import 'dart:async'; |
6 import 'dart:convert' show HtmlEscape; | |
7 import 'dart:io'; | 8 import 'dart:io'; |
8 | 9 |
9 import 'package:package_resolver/package_resolver.dart'; | 10 import 'dart:convert' show HtmlEscape; |
10 | 11 |
11 import 'configuration.dart'; | 12 import 'test_suite.dart'; // For TestUtils. |
12 import 'test_suite.dart'; | |
13 import 'vendored_pkg/args/args.dart'; | 13 import 'vendored_pkg/args/args.dart'; |
14 import 'utils.dart'; | 14 import 'utils.dart'; |
| 15 import 'package:package_resolver/package_resolver.dart'; |
15 | 16 |
16 class DispatchingServer { | 17 class DispatchingServer { |
17 HttpServer server; | 18 HttpServer server; |
18 Map<String, Function> _handlers = new Map<String, Function>(); | 19 Map<String, Function> _handlers = new Map<String, Function>(); |
19 Function _notFound; | 20 Function _notFound; |
20 | 21 |
21 DispatchingServer( | 22 DispatchingServer( |
22 this.server, void onError(e), void this._notFound(HttpRequest request)) { | 23 this.server, void onError(e), void this._notFound(HttpRequest request)) { |
23 server.listen(_dispatchRequest, onError: onError); | 24 server.listen(_dispatchRequest, onError: onError); |
24 } | 25 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 parser.addOption('runtime', | 87 parser.addOption('runtime', |
87 help: 'The runtime we are using (for csp flags).', defaultsTo: 'none'); | 88 help: 'The runtime we are using (for csp flags).', defaultsTo: 'none'); |
88 | 89 |
89 var args = parser.parse(arguments); | 90 var args = parser.parse(arguments); |
90 if (args['help'] as bool) { | 91 if (args['help'] as bool) { |
91 print(parser.getUsage()); | 92 print(parser.getUsage()); |
92 } else { | 93 } else { |
93 var servers = new TestingServers( | 94 var servers = new TestingServers( |
94 args['build-directory'] as String, | 95 args['build-directory'] as String, |
95 args['csp'] as bool, | 96 args['csp'] as bool, |
96 Runtime.find(args['runtime'] as String), | 97 args['runtime'] as String, |
97 null, | 98 null, |
98 args['package-root'] as String, | 99 args['package-root'] as String, |
99 args['packages'] as String); | 100 args['packages'] as String); |
100 var port = int.parse(args['port'] as String); | 101 var port = int.parse(args['port'] as String); |
101 var crossOriginPort = int.parse(args['crossOriginPort'] as String); | 102 var crossOriginPort = int.parse(args['crossOriginPort'] as String); |
102 servers | 103 servers |
103 .startServers(args['network'] as String, | 104 .startServers(args['network'] as String, |
104 port: port, crossOriginPort: crossOriginPort) | 105 port: port, crossOriginPort: crossOriginPort) |
105 .then((_) { | 106 .then((_) { |
106 DebugLogger.info('Server listening on port ${servers.port}'); | 107 DebugLogger.info('Server listening on port ${servers.port}'); |
(...skipping 17 matching lines...) Expand all Loading... |
124 "/NonExistingFile", | 125 "/NonExistingFile", |
125 "IntentionallyMissingFile", | 126 "IntentionallyMissingFile", |
126 ]; | 127 ]; |
127 | 128 |
128 final List<HttpServer> _serverList = []; | 129 final List<HttpServer> _serverList = []; |
129 Uri _buildDirectory; | 130 Uri _buildDirectory; |
130 Uri _dartDirectory; | 131 Uri _dartDirectory; |
131 Uri _packageRoot; | 132 Uri _packageRoot; |
132 Uri _packages; | 133 Uri _packages; |
133 final bool useContentSecurityPolicy; | 134 final bool useContentSecurityPolicy; |
134 final Runtime runtime; | 135 final String runtime; |
135 DispatchingServer _server; | 136 DispatchingServer _server; |
136 SyncPackageResolver _resolver; | 137 SyncPackageResolver _resolver; |
137 | 138 |
138 TestingServers(String buildDirectory, this.useContentSecurityPolicy, | 139 TestingServers(String buildDirectory, this.useContentSecurityPolicy, |
139 [this.runtime = Runtime.none, | 140 [String this.runtime = 'none', |
140 String dartDirectory, | 141 String dartDirectory, |
141 String packageRoot, | 142 String packageRoot, |
142 String packages]) { | 143 String packages]) { |
143 _buildDirectory = Uri.base.resolveUri(new Uri.directory(buildDirectory)); | 144 _buildDirectory = Uri.base.resolveUri(new Uri.directory(buildDirectory)); |
144 if (dartDirectory == null) { | 145 if (dartDirectory == null) { |
145 _dartDirectory = TestUtils.dartDirUri; | 146 _dartDirectory = TestUtils.dartDirUri; |
146 } else { | 147 } else { |
147 _dartDirectory = Uri.base.resolveUri(new Uri.directory(dartDirectory)); | 148 _dartDirectory = Uri.base.resolveUri(new Uri.directory(dartDirectory)); |
148 } | 149 } |
149 if (packageRoot == null) { | 150 if (packageRoot == null) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 var script = _dartDirectory.resolve('tools/testing/dart/http_server.dart'); | 187 var script = _dartDirectory.resolve('tools/testing/dart/http_server.dart'); |
187 var buildDirectory = _buildDirectory.toFilePath(); | 188 var buildDirectory = _buildDirectory.toFilePath(); |
188 var command = [ | 189 var command = [ |
189 dart, | 190 dart, |
190 script.toFilePath(), | 191 script.toFilePath(), |
191 '-p', | 192 '-p', |
192 port, | 193 port, |
193 '-c', | 194 '-c', |
194 crossOriginPort, | 195 crossOriginPort, |
195 '--build-directory=$buildDirectory', | 196 '--build-directory=$buildDirectory', |
196 '--runtime=${runtime.name}' | 197 '--runtime=$runtime' |
197 ]; | 198 ]; |
198 if (useContentSecurityPolicy) { | 199 if (useContentSecurityPolicy) { |
199 command.add('--csp'); | 200 command.add('--csp'); |
200 } | 201 } |
201 if (_packages != null) { | 202 if (_packages != null) { |
202 command.add('--packages=${_packages.toFilePath()}'); | 203 command.add('--packages=${_packages.toFilePath()}'); |
203 } else if (_packageRoot != null) { | 204 } else if (_packageRoot != null) { |
204 command.add('--package-root=${_packageRoot.toFilePath()}'); | 205 command.add('--package-root=${_packageRoot.toFilePath()}'); |
205 } | 206 } |
206 return command.join(' '); | 207 return command.join(' '); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 class _Entry implements Comparable<_Entry> { | 470 class _Entry implements Comparable<_Entry> { |
470 final String name; | 471 final String name; |
471 final String displayName; | 472 final String displayName; |
472 | 473 |
473 _Entry(this.name, this.displayName); | 474 _Entry(this.name, this.displayName); |
474 | 475 |
475 int compareTo(_Entry other) { | 476 int compareTo(_Entry other) { |
476 return name.compareTo(other.name); | 477 return name.compareTo(other.name); |
477 } | 478 } |
478 } | 479 } |
OLD | NEW |