| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 response.outputStream.close(); | 587 response.outputStream.close(); |
| 588 return; | 588 return; |
| 589 } | 589 } |
| 590 | 590 |
| 591 // Send the upgrade response. | 591 // Send the upgrade response. |
| 592 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; | 592 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; |
| 593 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); | 593 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); |
| 594 response.headers.add(HttpHeaders.UPGRADE, "websocket"); | 594 response.headers.add(HttpHeaders.UPGRADE, "websocket"); |
| 595 String key = request.headers.value("Sec-WebSocket-Key"); | 595 String key = request.headers.value("Sec-WebSocket-Key"); |
| 596 SHA1 sha1 = new SHA1(); | 596 SHA1 sha1 = new SHA1(); |
| 597 sha1.add("$key$_webSocketGUID".charCodes); | 597 sha1.add("$key$_webSocketGUID".codeUnits); |
| 598 String accept = _Base64._encode(sha1.close()); | 598 String accept = _Base64._encode(sha1.close()); |
| 599 response.headers.add("Sec-WebSocket-Accept", accept); | 599 response.headers.add("Sec-WebSocket-Accept", accept); |
| 600 response.contentLength = 0; | 600 response.contentLength = 0; |
| 601 | 601 |
| 602 // Upgrade the connection and get the underlying socket. | 602 // Upgrade the connection and get the underlying socket. |
| 603 WebSocketConnection conn = | 603 WebSocketConnection conn = |
| 604 new _WebSocketConnection(response.detachSocket()); | 604 new _WebSocketConnection(response.detachSocket()); |
| 605 if (_onOpen != null) _onOpen(conn); | 605 if (_onOpen != null) _onOpen(conn); |
| 606 } | 606 } |
| 607 | 607 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 if (!isUpgrade) return false; | 735 if (!isUpgrade) return false; |
| 736 String upgrade = response.headers.value(HttpHeaders.UPGRADE); | 736 String upgrade = response.headers.value(HttpHeaders.UPGRADE); |
| 737 if (upgrade == null || upgrade.toLowerCase() != "websocket") { | 737 if (upgrade == null || upgrade.toLowerCase() != "websocket") { |
| 738 return false; | 738 return false; |
| 739 } | 739 } |
| 740 String accept = response.headers.value("Sec-WebSocket-Accept"); | 740 String accept = response.headers.value("Sec-WebSocket-Accept"); |
| 741 if (accept == null) { | 741 if (accept == null) { |
| 742 return false; | 742 return false; |
| 743 } | 743 } |
| 744 SHA1 sha1 = new SHA1(); | 744 SHA1 sha1 = new SHA1(); |
| 745 sha1.add("$_nonce$_webSocketGUID".charCodes); | 745 sha1.add("$_nonce$_webSocketGUID".codeUnits); |
| 746 List<int> expectedAccept = sha1.close(); | 746 List<int> expectedAccept = sha1.close(); |
| 747 List<int> receivedAccept = _Base64._decode(accept); | 747 List<int> receivedAccept = _Base64._decode(accept); |
| 748 if (expectedAccept.length != receivedAccept.length) return false; | 748 if (expectedAccept.length != receivedAccept.length) return false; |
| 749 for (int i = 0; i < expectedAccept.length; i++) { | 749 for (int i = 0; i < expectedAccept.length; i++) { |
| 750 if (expectedAccept[i] != receivedAccept[i]) return false; | 750 if (expectedAccept[i] != receivedAccept[i]) return false; |
| 751 } | 751 } |
| 752 return true; | 752 return true; |
| 753 } | 753 } |
| 754 | 754 |
| 755 Function _onRequest; | 755 Function _onRequest; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 | 863 |
| 864 class _WebSocketCloseEvent implements CloseEvent { | 864 class _WebSocketCloseEvent implements CloseEvent { |
| 865 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 865 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 866 bool get wasClean => _wasClean; | 866 bool get wasClean => _wasClean; |
| 867 int get code => _code; | 867 int get code => _code; |
| 868 String get reason => _reason; | 868 String get reason => _reason; |
| 869 bool _wasClean; | 869 bool _wasClean; |
| 870 int _code; | 870 int _code; |
| 871 String _reason; | 871 String _reason; |
| 872 } | 872 } |
| OLD | NEW |