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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
8 | 8 |
9 class _WebSocketMessageType { | 9 class _WebSocketMessageType { |
10 static const int NONE = 0; | 10 static const int NONE = 0; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 static Future<WebSocket> _upgrade(HttpRequest request) { | 379 static Future<WebSocket> _upgrade(HttpRequest request) { |
380 var response = request.response; | 380 var response = request.response; |
381 if (!_isUpgradeRequest(request)) { | 381 if (!_isUpgradeRequest(request)) { |
382 // Send error response and drain the request. | 382 // Send error response and drain the request. |
383 request.listen((_) {}, onDone: () { | 383 request.listen((_) {}, onDone: () { |
384 response.statusCode = HttpStatus.BAD_REQUEST; | 384 response.statusCode = HttpStatus.BAD_REQUEST; |
385 response.contentLength = 0; | 385 response.contentLength = 0; |
386 response.close(); | 386 response.close(); |
387 }); | 387 }); |
388 return new Future.immediateError( | 388 return new Future.error( |
389 new WebSocketException("Invalid WebSocket upgrade request")); | 389 new WebSocketException("Invalid WebSocket upgrade request")); |
390 } | 390 } |
391 | 391 |
392 // Send the upgrade response. | 392 // Send the upgrade response. |
393 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; | 393 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; |
394 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); | 394 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); |
395 response.headers.add(HttpHeaders.UPGRADE, "websocket"); | 395 response.headers.add(HttpHeaders.UPGRADE, "websocket"); |
396 String key = request.headers.value("Sec-WebSocket-Key"); | 396 String key = request.headers.value("Sec-WebSocket-Key"); |
397 SHA1 sha1 = new SHA1(); | 397 SHA1 sha1 = new SHA1(); |
398 sha1.add("$key$_webSocketGUID".codeUnits); | 398 sha1.add("$key$_webSocketGUID".codeUnits); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 if (data != null) { | 687 if (data != null) { |
688 _socket.add(data); | 688 _socket.add(data); |
689 } | 689 } |
690 } catch (_) { | 690 } catch (_) { |
691 // The socket can be closed before _socket.done have a chance | 691 // The socket can be closed before _socket.done have a chance |
692 // to complete. | 692 // to complete. |
693 _writeClosed = true; | 693 _writeClosed = true; |
694 } | 694 } |
695 } | 695 } |
696 } | 696 } |
OLD | NEW |