| 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 'test_suite.dart'; // For TestUtils. | 9 import 'test_suite.dart'; // For TestUtils. |
| 10 // TODO(efortuna): Rewrite to not use the args library and simply take an | 10 // TODO(efortuna): Rewrite to not use the args library and simply take an |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 "/favicon.ico", | 94 "/favicon.ico", |
| 95 "/foo", | 95 "/foo", |
| 96 "/bar", | 96 "/bar", |
| 97 "/NonExistingFile", | 97 "/NonExistingFile", |
| 98 "/NonExistingFile.js", | 98 "/NonExistingFile.js", |
| 99 "/hahaURL", | 99 "/hahaURL", |
| 100 ]; | 100 ]; |
| 101 | 101 |
| 102 List _serverList = []; | 102 List _serverList = []; |
| 103 Path _buildDirectory = null; | 103 Path _buildDirectory = null; |
| 104 Path _dartDirectory = null; |
| 104 final bool useContentSecurityPolicy; | 105 final bool useContentSecurityPolicy; |
| 105 final String runtime; | 106 final String runtime; |
| 106 | 107 |
| 107 TestingServers(Path buildDirectory, | 108 TestingServers(Path buildDirectory, |
| 108 this.useContentSecurityPolicy, | 109 this.useContentSecurityPolicy, |
| 109 [String this.runtime = 'none']) { | 110 [String this.runtime = 'none', String dartDirectory]) { |
| 110 _buildDirectory = TestUtils.absolutePath(buildDirectory); | 111 _buildDirectory = TestUtils.absolutePath(buildDirectory); |
| 112 _dartDirectory = dartDirectory == null ? TestUtils.dartDir() |
| 113 : new Path(dartDirectory); |
| 111 } | 114 } |
| 112 | 115 |
| 113 int get port => _serverList[0].port; | 116 int get port => _serverList[0].port; |
| 114 int get crossOriginPort => _serverList[1].port; | 117 int get crossOriginPort => _serverList[1].port; |
| 115 | 118 |
| 116 /** | 119 /** |
| 117 * [startServers] will start two Http servers. | 120 * [startServers] will start two Http servers. |
| 118 * The first server listens on [port] and sets | 121 * The first server listens on [port] and sets |
| 119 * "Access-Control-Allow-Origin: *" | 122 * "Access-Control-Allow-Origin: *" |
| 120 * The second server listens on [crossOriginPort] and sets | 123 * The second server listens on [crossOriginPort] and sets |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 var requestPath = new Path(urlRequestPath.substring(1)).canonicalize(); | 234 var requestPath = new Path(urlRequestPath.substring(1)).canonicalize(); |
| 232 var pathSegments = requestPath.segments(); | 235 var pathSegments = requestPath.segments(); |
| 233 if (pathSegments.length > 0) { | 236 if (pathSegments.length > 0) { |
| 234 var basePath; | 237 var basePath; |
| 235 var relativePath; | 238 var relativePath; |
| 236 if (pathSegments[0] == PREFIX_BUILDDIR) { | 239 if (pathSegments[0] == PREFIX_BUILDDIR) { |
| 237 basePath = _buildDirectory; | 240 basePath = _buildDirectory; |
| 238 relativePath = new Path( | 241 relativePath = new Path( |
| 239 pathSegments.skip(1).join('/')); | 242 pathSegments.skip(1).join('/')); |
| 240 } else if (pathSegments[0] == PREFIX_DARTDIR) { | 243 } else if (pathSegments[0] == PREFIX_DARTDIR) { |
| 241 basePath = TestUtils.dartDir(); | 244 basePath = _dartDirectory; |
| 242 relativePath = new Path( | 245 relativePath = new Path( |
| 243 pathSegments.skip(1).join('/')); | 246 pathSegments.skip(1).join('/')); |
| 244 } | 247 } |
| 245 var packagesDirName = 'packages'; | 248 var packagesDirName = 'packages'; |
| 246 var packagesIndex = pathSegments.indexOf(packagesDirName); | 249 var packagesIndex = pathSegments.indexOf(packagesDirName); |
| 247 if (packagesIndex != -1) { | 250 if (packagesIndex != -1) { |
| 248 var start = packagesIndex + 1; | 251 var start = packagesIndex + 1; |
| 249 basePath = _buildDirectory.append(packagesDirName); | 252 basePath = _buildDirectory.append(packagesDirName); |
| 250 relativePath = new Path(pathSegments.skip(start).join('/')); | 253 relativePath = new Path(pathSegments.skip(start).join('/')); |
| 251 } | 254 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 class _Entry { | 390 class _Entry { |
| 388 final String name; | 391 final String name; |
| 389 final String displayName; | 392 final String displayName; |
| 390 | 393 |
| 391 _Entry(this.name, this.displayName); | 394 _Entry(this.name, this.displayName); |
| 392 | 395 |
| 393 int compareTo(_Entry other) { | 396 int compareTo(_Entry other) { |
| 394 return name.compareTo(other.name); | 397 return name.compareTo(other.name); |
| 395 } | 398 } |
| 396 } | 399 } |
| OLD | NEW |