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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 } | 653 } |
654 | 654 |
655 Random random = new Random(); | 655 Random random = new Random(); |
656 // Generate 16 random bytes. | 656 // Generate 16 random bytes. |
657 List<int> nonceData = new List<int>(16); | 657 List<int> nonceData = new List<int>(16); |
658 for (int i = 0; i < 16; i++) { | 658 for (int i = 0; i < 16; i++) { |
659 nonceData[i] = random.nextInt(256); | 659 nonceData[i] = random.nextInt(256); |
660 } | 660 } |
661 String nonce = CryptoUtils.bytesToBase64(nonceData); | 661 String nonce = CryptoUtils.bytesToBase64(nonceData); |
662 | 662 |
663 uri = new Uri.fromComponents(scheme: uri.scheme == "wss" ? "https" : "http", | 663 uri = new Uri(scheme: uri.scheme == "wss" ? "https" : "http", |
664 userInfo: uri.userInfo, | 664 userInfo: uri.userInfo, |
665 domain: uri.domain, | 665 host: uri.host, |
666 port: uri.port, | 666 port: uri.port, |
667 path: uri.path, | 667 path: uri.path, |
668 query: uri.query, | 668 query: uri.query, |
669 fragment: uri.fragment); | 669 fragment: uri.fragment); |
670 return _httpClient.openUrl("GET", uri) | 670 return _httpClient.openUrl("GET", uri) |
671 .then((request) { | 671 .then((request) { |
672 // Setup the initial handshake. | 672 // Setup the initial handshake. |
673 request.headers.add(HttpHeaders.CONNECTION, "upgrade"); | 673 request.headers.add(HttpHeaders.CONNECTION, "upgrade"); |
674 request.headers.set(HttpHeaders.UPGRADE, "websocket"); | 674 request.headers.set(HttpHeaders.UPGRADE, "websocket"); |
675 request.headers.set("Sec-WebSocket-Key", nonce); | 675 request.headers.set("Sec-WebSocket-Key", nonce); |
676 request.headers.set("Sec-WebSocket-Version", "13"); | 676 request.headers.set("Sec-WebSocket-Version", "13"); |
677 return request.close(); | 677 return request.close(); |
678 }) | 678 }) |
679 .then((response) { | 679 .then((response) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 (code < WebSocketStatus.NORMAL_CLOSURE || | 795 (code < WebSocketStatus.NORMAL_CLOSURE || |
796 code == WebSocketStatus.RESERVED_1004 || | 796 code == WebSocketStatus.RESERVED_1004 || |
797 code == WebSocketStatus.NO_STATUS_RECEIVED || | 797 code == WebSocketStatus.NO_STATUS_RECEIVED || |
798 code == WebSocketStatus.ABNORMAL_CLOSURE || | 798 code == WebSocketStatus.ABNORMAL_CLOSURE || |
799 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && | 799 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && |
800 code < WebSocketStatus.RESERVED_1015) || | 800 code < WebSocketStatus.RESERVED_1015) || |
801 (code >= WebSocketStatus.RESERVED_1015 && | 801 (code >= WebSocketStatus.RESERVED_1015 && |
802 code < 3000)); | 802 code < 3000)); |
803 } | 803 } |
804 } | 804 } |
OLD | NEW |