| 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 'test_suite.dart'; // For TestUtils. | 11 import 'test_suite.dart'; // For TestUtils. |
| 11 // TODO(efortuna): Rewrite to not use the args library and simply take an | 12 // TODO(efortuna): Rewrite to not use the args library and simply take an |
| 12 // expected number of arguments, so test.dart doesn't rely on the args library? | 13 // expected number of arguments, so test.dart doesn't rely on the args library? |
| 13 // See discussion on https://codereview.chromium.org/11931025/. | 14 // See discussion on https://codereview.chromium.org/11931025/. |
| 14 import 'vendored_pkg/args/args.dart'; | 15 import 'vendored_pkg/args/args.dart'; |
| 15 import 'utils.dart'; | 16 import 'utils.dart'; |
| 16 | 17 |
| 17 | 18 |
| 18 /// Interface of the HTTP server: | 19 /// Interface of the HTTP server: |
| 19 /// | 20 /// |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 response.headers.set("Access-Control-Allow-Origin", "*"); | 202 response.headers.set("Access-Control-Allow-Origin", "*"); |
| 202 request.pipe(response).catchError((e) { | 203 request.pipe(response).catchError((e) { |
| 203 DebugLogger.warning( | 204 DebugLogger.warning( |
| 204 'HttpServer: error while closing the response stream', e); | 205 'HttpServer: error while closing the response stream', e); |
| 205 }); | 206 }); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void _handleWebSocketRequest(HttpRequest request) { | 209 void _handleWebSocketRequest(HttpRequest request) { |
| 209 WebSocketTransformer.upgrade(request).then((websocket) { | 210 WebSocketTransformer.upgrade(request).then((websocket) { |
| 210 websocket.listen((data) { | 211 websocket.listen((data) { |
| 211 websocket.add(data); | 212 websocket.send(data); |
| 212 websocket.close(); | 213 websocket.close(); |
| 213 }, onError: (e) { | 214 }, onError: (e) { |
| 214 DebugLogger.warning('HttpServer: error while echoing to WebSocket', e); | 215 DebugLogger.warning('HttpServer: error while echoing to WebSocket', e); |
| 215 }); | 216 }); |
| 216 }).catchError((e) { | 217 }).catchError((e) { |
| 217 DebugLogger.warning( | 218 DebugLogger.warning( |
| 218 'HttpServer: error while transforming to WebSocket', e); | 219 'HttpServer: error while transforming to WebSocket', e); |
| 219 }); | 220 }); |
| 220 } | 221 } |
| 221 | 222 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 307 |
| 307 void _sendFileContent(HttpRequest request, | 308 void _sendFileContent(HttpRequest request, |
| 308 HttpResponse response, | 309 HttpResponse response, |
| 309 int allowedPort, | 310 int allowedPort, |
| 310 Path path, | 311 Path path, |
| 311 File file) { | 312 File file) { |
| 312 if (allowedPort != -1) { | 313 if (allowedPort != -1) { |
| 313 var headerOrigin = request.headers.value('Origin'); | 314 var headerOrigin = request.headers.value('Origin'); |
| 314 var allowedOrigin; | 315 var allowedOrigin; |
| 315 if (headerOrigin != null) { | 316 if (headerOrigin != null) { |
| 316 var origin = Uri.parse(headerOrigin); | 317 var origin = new Uri(headerOrigin); |
| 317 // Allow loading from http://*:$allowedPort in browsers. | 318 // Allow loading from http://*:$allowedPort in browsers. |
| 318 allowedOrigin = | 319 allowedOrigin = |
| 319 '${origin.scheme}://${origin.host}:${allowedPort}'; | 320 '${origin.scheme}://${origin.domain}:${allowedPort}'; |
| 320 } else { | 321 } else { |
| 321 // IE10 appears to be bugged and is not sending the Origin header | 322 // IE10 appears to be bugged and is not sending the Origin header |
| 322 // when making CORS requests to the same domain but different port. | 323 // when making CORS requests to the same domain but different port. |
| 323 allowedOrigin = '*'; | 324 allowedOrigin = '*'; |
| 324 } | 325 } |
| 325 | 326 |
| 326 | 327 |
| 327 response.headers.set("Access-Control-Allow-Origin", allowedOrigin); | 328 response.headers.set("Access-Control-Allow-Origin", allowedOrigin); |
| 328 response.headers.set('Access-Control-Allow-Credentials', 'true'); | 329 response.headers.set('Access-Control-Allow-Credentials', 'true'); |
| 329 } else { | 330 } else { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 class _Entry { | 381 class _Entry { |
| 381 final String name; | 382 final String name; |
| 382 final String displayName; | 383 final String displayName; |
| 383 | 384 |
| 384 _Entry(this.name, this.displayName); | 385 _Entry(this.name, this.displayName); |
| 385 | 386 |
| 386 int compareTo(_Entry other) { | 387 int compareTo(_Entry other) { |
| 387 return name.compareTo(other.name); | 388 return name.compareTo(other.name); |
| 388 } | 389 } |
| 389 } | 390 } |
| OLD | NEW |