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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 }); | 253 }); |
254 } | 254 } |
255 | 255 |
256 void _handleWebSocketRequest(HttpRequest request) { | 256 void _handleWebSocketRequest(HttpRequest request) { |
257 WebSocketTransformer.upgrade(request).then((websocket) { | 257 WebSocketTransformer.upgrade(request).then((websocket) { |
258 // We ignore failures to write to the socket, this happens if the browser | 258 // We ignore failures to write to the socket, this happens if the browser |
259 // closes the connection. | 259 // closes the connection. |
260 websocket.done.catchError((_) {}); | 260 websocket.done.catchError((_) {}); |
261 websocket.listen((data) { | 261 websocket.listen((data) { |
262 websocket.add(data); | 262 websocket.add(data); |
263 websocket.close(); | 263 if (data == 'close-with-error') { |
| 264 // Note: according to the web-sockets spec, a reason longer than 123 |
| 265 // bytes will produce a SyntaxError on the client. |
| 266 websocket.close(WebSocketStatus.UNSUPPORTED_DATA, 'X' * 124); |
| 267 } else { |
| 268 websocket.close(); |
| 269 } |
264 }, onError: (e) { | 270 }, onError: (e) { |
265 DebugLogger.warning('HttpServer: error while echoing to WebSocket', e); | 271 DebugLogger.warning('HttpServer: error while echoing to WebSocket', e); |
266 }); | 272 }); |
267 }).catchError((e) { | 273 }).catchError((e) { |
268 DebugLogger.warning( | 274 DebugLogger.warning( |
269 'HttpServer: error while transforming to WebSocket', e); | 275 'HttpServer: error while transforming to WebSocket', e); |
270 }); | 276 }); |
271 } | 277 } |
272 | 278 |
273 Path _getFilePathFromRequestPath(String urlRequestPath) { | 279 Path _getFilePathFromRequestPath(String urlRequestPath) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 class _Entry implements Comparable { | 462 class _Entry implements Comparable { |
457 final String name; | 463 final String name; |
458 final String displayName; | 464 final String displayName; |
459 | 465 |
460 _Entry(this.name, this.displayName); | 466 _Entry(this.name, this.displayName); |
461 | 467 |
462 int compareTo(_Entry other) { | 468 int compareTo(_Entry other) { |
463 return name.compareTo(other.name); | 469 return name.compareTo(other.name); |
464 } | 470 } |
465 } | 471 } |
OLD | NEW |