| 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 // Matches _WebSocketOpcode. | 9 // Matches _WebSocketOpcode. |
| 10 class _WebSocketMessageType { | 10 class _WebSocketMessageType { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 | 457 |
| 458 static bool _isUpgradeRequest(HttpRequest request) { | 458 static bool _isUpgradeRequest(HttpRequest request) { |
| 459 if (request.method != "GET") { | 459 if (request.method != "GET") { |
| 460 return false; | 460 return false; |
| 461 } | 461 } |
| 462 if (request.headers[HttpHeaders.CONNECTION] == null) { | 462 if (request.headers[HttpHeaders.CONNECTION] == null) { |
| 463 return false; | 463 return false; |
| 464 } | 464 } |
| 465 bool isUpgrade = false; | 465 bool isUpgrade = false; |
| 466 request.headers[HttpHeaders.CONNECTION].forEach((String value) { | 466 request.headers[HttpHeaders.CONNECTION].forEach((String value) { |
| 467 if (value.toLowerCase() == "upgrade") isUpgrade = true; | 467 if (_ASCII.toLowerCase(value) == "upgrade") isUpgrade = true; |
| 468 }); | 468 }); |
| 469 if (!isUpgrade) return false; | 469 if (!isUpgrade) return false; |
| 470 String upgrade = request.headers.value(HttpHeaders.UPGRADE); | 470 String upgrade = request.headers.value(HttpHeaders.UPGRADE); |
| 471 if (upgrade == null || upgrade.toLowerCase() != "websocket") { | 471 if (upgrade == null || _ASCII.toLowerCase(upgrade) != "websocket") { |
| 472 return false; | 472 return false; |
| 473 } | 473 } |
| 474 String version = request.headers.value("Sec-WebSocket-Version"); | 474 String version = request.headers.value("Sec-WebSocket-Version"); |
| 475 if (version == null || version != "13") { | 475 if (version == null || version != "13") { |
| 476 return false; | 476 return false; |
| 477 } | 477 } |
| 478 String key = request.headers.value("Sec-WebSocket-Key"); | 478 String key = request.headers.value("Sec-WebSocket-Key"); |
| 479 if (key == null) { | 479 if (key == null) { |
| 480 return false; | 480 return false; |
| 481 } | 481 } |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 void error(String message) { | 827 void error(String message) { |
| 828 // Flush data. | 828 // Flush data. |
| 829 response.detachSocket().then((socket) { | 829 response.detachSocket().then((socket) { |
| 830 socket.destroy(); | 830 socket.destroy(); |
| 831 }); | 831 }); |
| 832 throw new WebSocketException(message); | 832 throw new WebSocketException(message); |
| 833 } | 833 } |
| 834 if (response.statusCode != HttpStatus.SWITCHING_PROTOCOLS || | 834 if (response.statusCode != HttpStatus.SWITCHING_PROTOCOLS || |
| 835 response.headers[HttpHeaders.CONNECTION] == null || | 835 response.headers[HttpHeaders.CONNECTION] == null || |
| 836 !response.headers[HttpHeaders.CONNECTION].any( | 836 !response.headers[HttpHeaders.CONNECTION].any( |
| 837 (value) => value.toLowerCase() == "upgrade") || | 837 (value) => _ASCII.toLowerCase(value) == "upgrade") || |
| 838 response.headers.value(HttpHeaders.UPGRADE).toLowerCase() != | 838 _ASCII.toLowerCase(response.headers.value(HttpHeaders.UPGRADE)) != |
| 839 "websocket") { | 839 "websocket") { |
| 840 error("Connection to '$uri' was not upgraded to websocket"); | 840 error("Connection to '$uri' was not upgraded to websocket"); |
| 841 } | 841 } |
| 842 String accept = response.headers.value("Sec-WebSocket-Accept"); | 842 String accept = response.headers.value("Sec-WebSocket-Accept"); |
| 843 if (accept == null) { | 843 if (accept == null) { |
| 844 error("Response did not contain a 'Sec-WebSocket-Accept' header"); | 844 error("Response did not contain a 'Sec-WebSocket-Accept' header"); |
| 845 } | 845 } |
| 846 _SHA1 sha1 = new _SHA1(); | 846 _SHA1 sha1 = new _SHA1(); |
| 847 sha1.add("$nonce$_webSocketGUID".codeUnits); | 847 sha1.add("$nonce$_webSocketGUID".codeUnits); |
| 848 List<int> expectedAccept = sha1.close(); | 848 List<int> expectedAccept = sha1.close(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 (code < WebSocketStatus.NORMAL_CLOSURE || | 985 (code < WebSocketStatus.NORMAL_CLOSURE || |
| 986 code == WebSocketStatus.RESERVED_1004 || | 986 code == WebSocketStatus.RESERVED_1004 || |
| 987 code == WebSocketStatus.NO_STATUS_RECEIVED || | 987 code == WebSocketStatus.NO_STATUS_RECEIVED || |
| 988 code == WebSocketStatus.ABNORMAL_CLOSURE || | 988 code == WebSocketStatus.ABNORMAL_CLOSURE || |
| 989 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && | 989 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && |
| 990 code < WebSocketStatus.RESERVED_1015) || | 990 code < WebSocketStatus.RESERVED_1015) || |
| 991 (code >= WebSocketStatus.RESERVED_1015 && | 991 (code >= WebSocketStatus.RESERVED_1015 && |
| 992 code < 3000)); | 992 code < 3000)); |
| 993 } | 993 } |
| 994 } | 994 } |
| OLD | NEW |