| 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 const String _clientNoContextTakeover = "client_no_context_takeover"; | 8 const String _clientNoContextTakeover = "client_no_context_takeover"; |
| 9 const String _serverNoContextTakeover = "server_no_context_takeover"; | 9 const String _serverNoContextTakeover = "server_no_context_takeover"; |
| 10 const String _clientMaxWindowBits = "client_max_window_bits"; | 10 const String _clientMaxWindowBits = "client_max_window_bits"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 static const int CLOSE = 8; | 29 static const int CLOSE = 8; |
| 30 static const int PING = 9; | 30 static const int PING = 9; |
| 31 static const int PONG = 10; | 31 static const int PONG = 10; |
| 32 static const int RESERVED_B = 11; | 32 static const int RESERVED_B = 11; |
| 33 static const int RESERVED_C = 12; | 33 static const int RESERVED_C = 12; |
| 34 static const int RESERVED_D = 13; | 34 static const int RESERVED_D = 13; |
| 35 static const int RESERVED_E = 14; | 35 static const int RESERVED_E = 14; |
| 36 static const int RESERVED_F = 15; | 36 static const int RESERVED_F = 15; |
| 37 } | 37 } |
| 38 | 38 |
| 39 class _EncodedString { |
| 40 final List<int> bytes; |
| 41 _EncodedString(this.bytes); |
| 42 } |
| 43 |
| 39 /** | 44 /** |
| 40 * Stores the header and integer value derived from negotiation of | 45 * Stores the header and integer value derived from negotiation of |
| 41 * client_max_window_bits and server_max_window_bits. headerValue will be | 46 * client_max_window_bits and server_max_window_bits. headerValue will be |
| 42 * set in the Websocket response headers. | 47 * set in the Websocket response headers. |
| 43 */ | 48 */ |
| 44 class _CompressionMaxWindowBits { | 49 class _CompressionMaxWindowBits { |
| 45 String headerValue; | 50 String headerValue; |
| 46 int maxWindowBits; | 51 int maxWindowBits; |
| 47 _CompressionMaxWindowBits([this.headerValue, this.maxWindowBits]); | 52 _CompressionMaxWindowBits([this.headerValue, this.maxWindowBits]); |
| 48 String toString() => headerValue; | 53 String toString() => headerValue; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 if (message is _WebSocketPing) { | 668 if (message is _WebSocketPing) { |
| 664 addFrame(_WebSocketOpcode.PING, message.payload); | 669 addFrame(_WebSocketOpcode.PING, message.payload); |
| 665 return; | 670 return; |
| 666 } | 671 } |
| 667 List<int> data; | 672 List<int> data; |
| 668 int opcode; | 673 int opcode; |
| 669 if (message != null) { | 674 if (message != null) { |
| 670 if (message is String) { | 675 if (message is String) { |
| 671 opcode = _WebSocketOpcode.TEXT; | 676 opcode = _WebSocketOpcode.TEXT; |
| 672 data = UTF8.encode(message); | 677 data = UTF8.encode(message); |
| 678 } else if (message is List<int>) { |
| 679 opcode = _WebSocketOpcode.BINARY; |
| 680 data = message; |
| 681 } else if (message is _EncodedString) { |
| 682 opcode = _WebSocketOpcode.TEXT; |
| 683 data = message.bytes; |
| 673 } else { | 684 } else { |
| 674 if (message is List<int>) { | 685 throw new ArgumentError(message); |
| 675 opcode = _WebSocketOpcode.BINARY; | |
| 676 data = message; | |
| 677 } else { | |
| 678 throw new ArgumentError(message); | |
| 679 } | |
| 680 } | 686 } |
| 681 | 687 |
| 682 if (_deflateHelper != null) { | 688 if (_deflateHelper != null) { |
| 683 data = _deflateHelper.processOutgoingMessage(data); | 689 data = _deflateHelper.processOutgoingMessage(data); |
| 684 } | 690 } |
| 685 } else { | 691 } else { |
| 686 opcode = _WebSocketOpcode.TEXT; | 692 opcode = _WebSocketOpcode.TEXT; |
| 687 } | 693 } |
| 688 addFrame(opcode, data); | 694 addFrame(opcode, data); |
| 689 } | 695 } |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 }); | 1174 }); |
| 1169 }); | 1175 }); |
| 1170 } | 1176 } |
| 1171 | 1177 |
| 1172 int get readyState => _readyState; | 1178 int get readyState => _readyState; |
| 1173 | 1179 |
| 1174 String get extensions => null; | 1180 String get extensions => null; |
| 1175 int get closeCode => _closeCode; | 1181 int get closeCode => _closeCode; |
| 1176 String get closeReason => _closeReason; | 1182 String get closeReason => _closeReason; |
| 1177 | 1183 |
| 1184 void sendMessage(WebSocketMessageType type, List<int> bytes) { |
| 1185 if (bytes is! List<int>) { |
| 1186 throw new ArgumentError(bytes); |
| 1187 } |
| 1188 switch (type) { |
| 1189 case WebSocketMessageType.BINARY: |
| 1190 add(bytes); |
| 1191 break; |
| 1192 case WebSocketMessageType.TEXT: |
| 1193 add(new _EncodedString(bytes)); |
| 1194 break; |
| 1195 default: |
| 1196 throw new ArgumentError(type); |
| 1197 } |
| 1198 } |
| 1199 |
| 1178 void add(data) { _sink.add(data); } | 1200 void add(data) { _sink.add(data); } |
| 1179 void addError(error, [StackTrace stackTrace]) { | 1201 void addError(error, [StackTrace stackTrace]) { |
| 1180 _sink.addError(error, stackTrace); | 1202 _sink.addError(error, stackTrace); |
| 1181 } | 1203 } |
| 1182 Future addStream(Stream stream) => _sink.addStream(stream); | 1204 Future addStream(Stream stream) => _sink.addStream(stream); |
| 1183 Future get done => _sink.done; | 1205 Future get done => _sink.done; |
| 1184 | 1206 |
| 1185 Future close([int code, String reason]) { | 1207 Future close([int code, String reason]) { |
| 1186 if (_isReservedStatusCode(code)) { | 1208 if (_isReservedStatusCode(code)) { |
| 1187 throw new WebSocketException("Reserved status code $code"); | 1209 throw new WebSocketException("Reserved status code $code"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 return code != null && | 1278 return code != null && |
| 1257 (code < WebSocketStatus.NORMAL_CLOSURE || | 1279 (code < WebSocketStatus.NORMAL_CLOSURE || |
| 1258 code == WebSocketStatus.RESERVED_1004 || | 1280 code == WebSocketStatus.RESERVED_1004 || |
| 1259 code == WebSocketStatus.NO_STATUS_RECEIVED || | 1281 code == WebSocketStatus.NO_STATUS_RECEIVED || |
| 1260 code == WebSocketStatus.ABNORMAL_CLOSURE || | 1282 code == WebSocketStatus.ABNORMAL_CLOSURE || |
| 1261 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && | 1283 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && |
| 1262 code < WebSocketStatus.RESERVED_1015) || | 1284 code < WebSocketStatus.RESERVED_1015) || |
| 1263 (code >= WebSocketStatus.RESERVED_1015 && code < 3000)); | 1285 (code >= WebSocketStatus.RESERVED_1015 && code < 3000)); |
| 1264 } | 1286 } |
| 1265 } | 1287 } |
| OLD | NEW |