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