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 | 9 |
10 import 'dart:convert' show HtmlEscape; | 10 import 'dart:convert' show HtmlEscape; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 parser.addOption('package-root', help: 'The package root to use.'); | 81 parser.addOption('package-root', help: 'The package root to use.'); |
82 parser.addOption('packages', help: 'The package spec file to use.'); | 82 parser.addOption('packages', help: 'The package spec file to use.'); |
83 parser.addOption('network', | 83 parser.addOption('network', |
84 help: 'The network interface to use.', defaultsTo: '0.0.0.0'); | 84 help: 'The network interface to use.', defaultsTo: '0.0.0.0'); |
85 parser.addFlag('csp', | 85 parser.addFlag('csp', |
86 help: 'Use Content Security Policy restrictions.', defaultsTo: false); | 86 help: 'Use Content Security Policy restrictions.', defaultsTo: false); |
87 parser.addOption('runtime', | 87 parser.addOption('runtime', |
88 help: 'The runtime we are using (for csp flags).', defaultsTo: 'none'); | 88 help: 'The runtime we are using (for csp flags).', defaultsTo: 'none'); |
89 | 89 |
90 var args = parser.parse(arguments); | 90 var args = parser.parse(arguments); |
91 if (args['help']) { | 91 if (args['help'] as bool) { |
92 print(parser.getUsage()); | 92 print(parser.getUsage()); |
93 } else { | 93 } else { |
94 var servers = new TestingServers(args['build-directory'], args['csp'], | 94 var servers = new TestingServers( |
95 args['runtime'], null, args['package-root'], args['packages']); | 95 args['build-directory'] as String, |
96 var port = int.parse(args['port']); | 96 args['csp'] as bool, |
97 var crossOriginPort = int.parse(args['crossOriginPort']); | 97 args['runtime'] as String, |
| 98 null, |
| 99 args['package-root'] as String, |
| 100 args['packages'] as String); |
| 101 var port = int.parse(args['port'] as String); |
| 102 var crossOriginPort = int.parse(args['crossOriginPort'] as String); |
98 servers | 103 servers |
99 .startServers(args['network'], | 104 .startServers(args['network'] as String, |
100 port: port, crossOriginPort: crossOriginPort) | 105 port: port, crossOriginPort: crossOriginPort) |
101 .then((_) { | 106 .then((_) { |
102 DebugLogger.info('Server listening on port ${servers.port}'); | 107 DebugLogger.info('Server listening on port ${servers.port}'); |
103 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); | 108 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); |
104 }); | 109 }); |
105 } | 110 } |
106 } | 111 } |
107 | 112 |
108 /** | 113 /** |
109 * Runs a set of servers that are initialized specifically for the needs of our | 114 * Runs a set of servers that are initialized specifically for the needs of our |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 void stopServers() { | 210 void stopServers() { |
206 for (var server in _serverList) { | 211 for (var server in _serverList) { |
207 server.close(); | 212 server.close(); |
208 } | 213 } |
209 } | 214 } |
210 | 215 |
211 void _onError(e) { | 216 void _onError(e) { |
212 DebugLogger.error('HttpServer: an error occured', e); | 217 DebugLogger.error('HttpServer: an error occured', e); |
213 } | 218 } |
214 | 219 |
215 Future _startHttpServer(String host, {int port: 0, int allowedPort: -1}) { | 220 Future<DispatchingServer> _startHttpServer(String host, |
| 221 {int port: 0, int allowedPort: -1}) { |
216 return HttpServer.bind(host, port).then((HttpServer httpServer) { | 222 return HttpServer.bind(host, port).then((HttpServer httpServer) { |
217 var server = new DispatchingServer(httpServer, _onError, _sendNotFound); | 223 var server = new DispatchingServer(httpServer, _onError, _sendNotFound); |
218 server.addHandler('/echo', _handleEchoRequest); | 224 server.addHandler('/echo', _handleEchoRequest); |
219 server.addHandler('/ws', _handleWebSocketRequest); | 225 server.addHandler('/ws', _handleWebSocketRequest); |
220 fileHandler(HttpRequest request) { | 226 fileHandler(HttpRequest request) { |
221 _handleFileOrDirectoryRequest(request, allowedPort); | 227 _handleFileOrDirectoryRequest(request, allowedPort); |
222 } | 228 } |
223 | 229 |
224 server.addHandler('/$PREFIX_BUILDDIR', fileHandler); | 230 server.addHandler('/$PREFIX_BUILDDIR', fileHandler); |
225 server.addHandler('/$PREFIX_DARTDIR', fileHandler); | 231 server.addHandler('/$PREFIX_DARTDIR', fileHandler); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 class _Entry implements Comparable<_Entry> { | 470 class _Entry implements Comparable<_Entry> { |
465 final String name; | 471 final String name; |
466 final String displayName; | 472 final String displayName; |
467 | 473 |
468 _Entry(this.name, this.displayName); | 474 _Entry(this.name, this.displayName); |
469 | 475 |
470 int compareTo(_Entry other) { | 476 int compareTo(_Entry other) { |
471 return name.compareTo(other.name); | 477 return name.compareTo(other.name); |
472 } | 478 } |
473 } | 479 } |
OLD | NEW |