| 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 | 10 import 'dart:convert' show |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 /// Interface of the HTTP server: | 50 /// Interface of the HTTP server: |
| 51 /// | 51 /// |
| 52 /// /echo: This will stream the data received in the request stream back | 52 /// /echo: This will stream the data received in the request stream back |
| 53 /// to the client. | 53 /// to the client. |
| 54 /// /root_dart/X: This will serve the corresponding file from the dart | 54 /// /root_dart/X: This will serve the corresponding file from the dart |
| 55 /// directory (i.e. '$DartDirectory/X'). | 55 /// directory (i.e. '$DartDirectory/X'). |
| 56 /// /root_build/X: This will serve the corresponding file from the build | 56 /// /root_build/X: This will serve the corresponding file from the build |
| 57 /// directory (i.e. '$BuildDirectory/X'). | 57 /// directory (i.e. '$BuildDirectory/X'). |
| 58 /// /FOO/packages/BAR: This will serve the corresponding file from the packages | 58 /// /FOO/packages/BAR: This will serve the corresponding file from the packages |
| 59 /// directory (i.e. '$BuildDirectory/packages/BAR') or the | 59 /// directory (i.e. '$BuildDirectory/packages/BAR') or the |
| 60 /// passed-in package root | 60 /// passed-in package root |
| 61 /// /ws: This will upgrade the connection to a WebSocket connection and echo | 61 /// /ws: This will upgrade the connection to a WebSocket connection and echo |
| 62 /// all data back to the client. | 62 /// all data back to the client. |
| 63 /// | 63 /// |
| 64 /// In case a path does not refer to a file but rather to a directory, a | 64 /// In case a path does not refer to a file but rather to a directory, a |
| 65 /// directory listing will be displayed. | 65 /// directory listing will be displayed. |
| 66 | 66 |
| 67 const PREFIX_BUILDDIR = 'root_build'; | 67 const PREFIX_BUILDDIR = 'root_build'; |
| 68 const PREFIX_DARTDIR = 'root_dart'; | 68 const PREFIX_DARTDIR = 'root_dart'; |
| 69 | 69 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 final String runtime; | 137 final String runtime; |
| 138 DispatchingServer _server; | 138 DispatchingServer _server; |
| 139 | 139 |
| 140 TestingServers(Path buildDirectory, | 140 TestingServers(Path buildDirectory, |
| 141 this.useContentSecurityPolicy, | 141 this.useContentSecurityPolicy, |
| 142 [String this.runtime = 'none', String dartDirectory, | 142 [String this.runtime = 'none', String dartDirectory, |
| 143 String packageRoot]) { | 143 String packageRoot]) { |
| 144 _buildDirectory = TestUtils.absolutePath(buildDirectory); | 144 _buildDirectory = TestUtils.absolutePath(buildDirectory); |
| 145 _dartDirectory = dartDirectory == null ? TestUtils.dartDir | 145 _dartDirectory = dartDirectory == null ? TestUtils.dartDir |
| 146 : new Path(dartDirectory); | 146 : new Path(dartDirectory); |
| 147 _packageRoot = packageRoot == null ? | 147 _packageRoot = packageRoot == null ? |
| 148 _buildDirectory.append('packages') : | 148 _buildDirectory.append('packages') : |
| 149 new Path(packageRoot); | 149 new Path(packageRoot); |
| 150 } | 150 } |
| 151 | 151 |
| 152 int get port => _serverList[0].port; | 152 int get port => _serverList[0].port; |
| 153 int get crossOriginPort => _serverList[1].port; | 153 int get crossOriginPort => _serverList[1].port; |
| 154 DispatchingServer get server => _server; | 154 DispatchingServer get server => _server; |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * [startServers] will start two Http servers. | 157 * [startServers] will start two Http servers. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if (const ["safari"].contains(runtime)) { | 392 if (const ["safari"].contains(runtime)) { |
| 393 response.headers.set("X-WebKit-CSP", content_header_value); | 393 response.headers.set("X-WebKit-CSP", content_header_value); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 if (path.filename.endsWith('.html')) { | 396 if (path.filename.endsWith('.html')) { |
| 397 response.headers.set('Content-Type', 'text/html'); | 397 response.headers.set('Content-Type', 'text/html'); |
| 398 } else if (path.filename.endsWith('.js')) { | 398 } else if (path.filename.endsWith('.js')) { |
| 399 response.headers.set('Content-Type', 'application/javascript'); | 399 response.headers.set('Content-Type', 'application/javascript'); |
| 400 } else if (path.filename.endsWith('.dart')) { | 400 } else if (path.filename.endsWith('.dart')) { |
| 401 response.headers.set('Content-Type', 'application/dart'); | 401 response.headers.set('Content-Type', 'application/dart'); |
| 402 } else if (path.filename.endsWith('.css')) { |
| 403 response.headers.set('Content-Type', 'text/css'); |
| 402 } | 404 } |
| 403 response.headers.removeAll("X-Frame-Options"); | 405 response.headers.removeAll("X-Frame-Options"); |
| 404 file.openRead().pipe(response).catchError((e) { | 406 file.openRead().pipe(response).catchError((e) { |
| 405 DebugLogger.warning( | 407 DebugLogger.warning( |
| 406 'HttpServer: error while closing the response stream', e); | 408 'HttpServer: error while closing the response stream', e); |
| 407 }); | 409 }); |
| 408 } | 410 } |
| 409 | 411 |
| 410 void _sendNotFound(HttpRequest request) { | 412 void _sendNotFound(HttpRequest request) { |
| 411 bool isHarmlessPath(String path) { | 413 bool isHarmlessPath(String path) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 class _Entry implements Comparable { | 453 class _Entry implements Comparable { |
| 452 final String name; | 454 final String name; |
| 453 final String displayName; | 455 final String displayName; |
| 454 | 456 |
| 455 _Entry(this.name, this.displayName); | 457 _Entry(this.name, this.displayName); |
| 456 | 458 |
| 457 int compareTo(_Entry other) { | 459 int compareTo(_Entry other) { |
| 458 return name.compareTo(other.name); | 460 return name.compareTo(other.name); |
| 459 } | 461 } |
| 460 } | 462 } |
| OLD | NEW |