| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 Uri uri = Uri.parse(url); | 440 Uri uri = Uri.parse(url); |
| 441 if (uri.scheme != "ws" && uri.scheme != "wss") { | 441 if (uri.scheme != "ws" && uri.scheme != "wss") { |
| 442 throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'"); | 442 throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'"); |
| 443 } | 443 } |
| 444 if (uri.userInfo != "") { | 444 if (uri.userInfo != "") { |
| 445 throw new WebSocketException("Unsupported user info '${uri.userInfo}'"); | 445 throw new WebSocketException("Unsupported user info '${uri.userInfo}'"); |
| 446 } | 446 } |
| 447 | 447 |
| 448 Random random = new Random(); | 448 Random random = new Random(); |
| 449 // Generate 16 random bytes. | 449 // Generate 16 random bytes. |
| 450 List<int> nonceData = new List<int>.fixedLength(16); | 450 List<int> nonceData = new List<int>(16); |
| 451 for (int i = 0; i < 16; i++) { | 451 for (int i = 0; i < 16; i++) { |
| 452 nonceData[i] = random.nextInt(256); | 452 nonceData[i] = random.nextInt(256); |
| 453 } | 453 } |
| 454 String nonce = _Base64._encode(nonceData); | 454 String nonce = _Base64._encode(nonceData); |
| 455 | 455 |
| 456 uri = new Uri.fromComponents(scheme: uri.scheme == "wss" ? "https" : "http", | 456 uri = new Uri.fromComponents(scheme: uri.scheme == "wss" ? "https" : "http", |
| 457 userInfo: uri.userInfo, | 457 userInfo: uri.userInfo, |
| 458 domain: uri.domain, | 458 domain: uri.domain, |
| 459 port: uri.port, | 459 port: uri.port, |
| 460 path: uri.path, | 460 path: uri.path, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 void _sendFrame(int opcode, [List<int> data]) { | 633 void _sendFrame(int opcode, [List<int> data]) { |
| 634 bool mask = false; // Masking not implemented for server. | 634 bool mask = false; // Masking not implemented for server. |
| 635 int dataLength = data == null ? 0 : data.length; | 635 int dataLength = data == null ? 0 : data.length; |
| 636 // Determine the header size. | 636 // Determine the header size. |
| 637 int headerSize = (mask) ? 6 : 2; | 637 int headerSize = (mask) ? 6 : 2; |
| 638 if (dataLength > 65535) { | 638 if (dataLength > 65535) { |
| 639 headerSize += 8; | 639 headerSize += 8; |
| 640 } else if (dataLength > 125) { | 640 } else if (dataLength > 125) { |
| 641 headerSize += 2; | 641 headerSize += 2; |
| 642 } | 642 } |
| 643 List<int> header = new List<int>.fixedLength(headerSize); | 643 List<int> header = new List<int>(headerSize); |
| 644 int index = 0; | 644 int index = 0; |
| 645 // Set FIN and opcode. | 645 // Set FIN and opcode. |
| 646 header[index++] = 0x80 | opcode; | 646 header[index++] = 0x80 | opcode; |
| 647 // Determine size and position of length field. | 647 // Determine size and position of length field. |
| 648 int lengthBytes = 1; | 648 int lengthBytes = 1; |
| 649 int firstLengthByte = 1; | 649 int firstLengthByte = 1; |
| 650 if (dataLength > 65535) { | 650 if (dataLength > 65535) { |
| 651 header[index++] = 127; | 651 header[index++] = 127; |
| 652 lengthBytes = 8; | 652 lengthBytes = 8; |
| 653 } else if (dataLength > 125) { | 653 } else if (dataLength > 125) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 676 | 676 |
| 677 class _WebSocketCloseEvent implements CloseEvent { | 677 class _WebSocketCloseEvent implements CloseEvent { |
| 678 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 678 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 679 bool get wasClean => _wasClean; | 679 bool get wasClean => _wasClean; |
| 680 int get code => _code; | 680 int get code => _code; |
| 681 String get reason => _reason; | 681 String get reason => _reason; |
| 682 bool _wasClean; | 682 bool _wasClean; |
| 683 int _code; | 683 int _code; |
| 684 String _reason; | 684 String _reason; |
| 685 } | 685 } |
| OLD | NEW |