| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); | 82 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); |
| 83 }); | 83 }); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Runs a set of servers that are initialized specifically for the needs of our | 88 * Runs a set of servers that are initialized specifically for the needs of our |
| 89 * test framework, such as dealing with package-root. | 89 * test framework, such as dealing with package-root. |
| 90 */ | 90 */ |
| 91 class TestingServers { | 91 class TestingServers { |
| 92 static final _HARMLESS_REQUEST_PATH_ENDINGS = [ |
| 93 "/apple-touch-icon.png", |
| 94 "/apple-touch-icon-precomposed.png", |
| 95 "/favicon.ico", |
| 96 "/foo", |
| 97 "/bar", |
| 98 "/NonExistingFile", |
| 99 "/hahaURL", |
| 100 ]; |
| 101 |
| 92 List _serverList = []; | 102 List _serverList = []; |
| 93 Path _buildDirectory = null; | 103 Path _buildDirectory = null; |
| 94 final bool useContentSecurityPolicy; | 104 final bool useContentSecurityPolicy; |
| 95 final String runtime; | 105 final String runtime; |
| 96 | 106 |
| 97 TestingServers(Path buildDirectory, | 107 TestingServers(Path buildDirectory, |
| 98 this.useContentSecurityPolicy, | 108 this.useContentSecurityPolicy, |
| 99 [String this.runtime = 'none']) { | 109 [String this.runtime = 'none']) { |
| 100 _buildDirectory = TestUtils.absolutePath(buildDirectory); | 110 _buildDirectory = TestUtils.absolutePath(buildDirectory); |
| 101 } | 111 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } else if (path.filename.endsWith('.dart')) { | 352 } else if (path.filename.endsWith('.dart')) { |
| 343 response.headers.set('Content-Type', 'application/dart'); | 353 response.headers.set('Content-Type', 'application/dart'); |
| 344 } | 354 } |
| 345 file.openRead().pipe(response).catchError((e) { | 355 file.openRead().pipe(response).catchError((e) { |
| 346 DebugLogger.warning( | 356 DebugLogger.warning( |
| 347 'HttpServer: error while closing the response stream', e); | 357 'HttpServer: error while closing the response stream', e); |
| 348 }); | 358 }); |
| 349 } | 359 } |
| 350 | 360 |
| 351 void _sendNotFound(HttpRequest request, HttpResponse response) { | 361 void _sendNotFound(HttpRequest request, HttpResponse response) { |
| 352 // NOTE: Since some tests deliberately try to access non-existent files. | 362 bool isHarmlessPath(String path) { |
| 353 // We might want to remove this warning (otherwise it will show | 363 return _HARMLESS_REQUEST_PATH_ENDINGS.any((ending) { |
| 354 // up in the debug.log every time). | 364 return path.endsWith(ending); |
| 355 if (request.uri.path != "/favicon.ico") { | 365 }); |
| 366 } |
| 367 if (!isHarmlessPath(request.uri.path)) { |
| 356 DebugLogger.warning('HttpServer: could not find file for request path: ' | 368 DebugLogger.warning('HttpServer: could not find file for request path: ' |
| 357 '"${request.uri.path}"'); | 369 '"${request.uri.path}"'); |
| 358 } | 370 } |
| 359 response.statusCode = HttpStatus.NOT_FOUND; | 371 response.statusCode = HttpStatus.NOT_FOUND; |
| 360 response.close(); | 372 response.close(); |
| 361 response.done.catchError((e) { | 373 response.done.catchError((e) { |
| 362 DebugLogger.warning( | 374 DebugLogger.warning( |
| 363 'HttpServer: error while closing the response stream', e); | 375 'HttpServer: error while closing the response stream', e); |
| 364 }); | 376 }); |
| 365 } | 377 } |
| 366 } | 378 } |
| 367 | 379 |
| 368 // Helper class for displaying directory listings. | 380 // Helper class for displaying directory listings. |
| 369 class _Entry { | 381 class _Entry { |
| 370 final String name; | 382 final String name; |
| 371 final String displayName; | 383 final String displayName; |
| 372 | 384 |
| 373 _Entry(this.name, this.displayName); | 385 _Entry(this.name, this.displayName); |
| 374 | 386 |
| 375 int compareTo(_Entry other) { | 387 int compareTo(_Entry other) { |
| 376 return name.compareTo(other.name); | 388 return name.compareTo(other.name); |
| 377 } | 389 } |
| 378 } | 390 } |
| OLD | NEW |