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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 88 } |
89 break; | 89 break; |
90 | 90 |
91 case _WebSocketOpcode.TEXT: | 91 case _WebSocketOpcode.TEXT: |
92 if (_currentMessageType != _WebSocketMessageType.NONE) { | 92 if (_currentMessageType != _WebSocketMessageType.NONE) { |
93 throw new WebSocketException("Protocol error"); | 93 throw new WebSocketException("Protocol error"); |
94 } | 94 } |
95 _currentMessageType = _WebSocketMessageType.TEXT; | 95 _currentMessageType = _WebSocketMessageType.TEXT; |
96 _controller = new StreamController(sync: true); | 96 _controller = new StreamController(sync: true); |
97 _controller.stream | 97 _controller.stream |
98 .transform(new Utf8DecoderTransformer(null)) | 98 .transform(UTF8.decoder) |
99 .fold(new StringBuffer(), (buffer, str) => buffer..write(str)) | 99 .fold(new StringBuffer(), (buffer, str) => buffer..write(str)) |
100 .then((buffer) { | 100 .then((buffer) { |
101 sink.add(buffer.toString()); | 101 sink.add(buffer.toString()); |
102 }, onError: (error) { | 102 }, onError: (error) { |
103 sink.addError(error); | 103 sink.addError(error); |
104 }); | 104 }); |
105 break; | 105 break; |
106 | 106 |
107 case _WebSocketOpcode.BINARY: | 107 case _WebSocketOpcode.BINARY: |
108 if (_currentMessageType != _WebSocketMessageType.NONE) { | 108 if (_currentMessageType != _WebSocketMessageType.NONE) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 closeCode = WebSocketStatus.NO_STATUS_RECEIVED; | 297 closeCode = WebSocketStatus.NO_STATUS_RECEIVED; |
298 if (_controlPayload.length > 0) { | 298 if (_controlPayload.length > 0) { |
299 if (_controlPayload.length == 1) { | 299 if (_controlPayload.length == 1) { |
300 throw new WebSocketException("Protocol error"); | 300 throw new WebSocketException("Protocol error"); |
301 } | 301 } |
302 closeCode = _controlPayload[0] << 8 | _controlPayload[1]; | 302 closeCode = _controlPayload[0] << 8 | _controlPayload[1]; |
303 if (closeCode == WebSocketStatus.NO_STATUS_RECEIVED) { | 303 if (closeCode == WebSocketStatus.NO_STATUS_RECEIVED) { |
304 throw new WebSocketException("Protocol error"); | 304 throw new WebSocketException("Protocol error"); |
305 } | 305 } |
306 if (_controlPayload.length > 2) { | 306 if (_controlPayload.length > 2) { |
307 closeReason = _decodeUtf8Strict(_controlPayload.sublist(2)); | 307 closeReason = _decodeUtf8Strict(_controlPayload.sublist(2)); |
Anders Johnsen
2013/08/23 06:07:12
NYC, but you can remove the _decodeUtf8Strict by j
floitsch
2013/08/23 08:51:59
Done.
| |
308 } | 308 } |
309 } | 309 } |
310 _state = CLOSED; | 310 _state = CLOSED; |
311 sink.close(); | 311 sink.close(); |
312 break; | 312 break; |
313 | 313 |
314 case _WebSocketOpcode.PING: | 314 case _WebSocketOpcode.PING: |
315 sink.add(new _WebSocketPing(_controlPayload)); | 315 sink.add(new _WebSocketPing(_controlPayload)); |
316 break; | 316 break; |
317 | 317 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 (code < WebSocketStatus.NORMAL_CLOSURE || | 874 (code < WebSocketStatus.NORMAL_CLOSURE || |
875 code == WebSocketStatus.RESERVED_1004 || | 875 code == WebSocketStatus.RESERVED_1004 || |
876 code == WebSocketStatus.NO_STATUS_RECEIVED || | 876 code == WebSocketStatus.NO_STATUS_RECEIVED || |
877 code == WebSocketStatus.ABNORMAL_CLOSURE || | 877 code == WebSocketStatus.ABNORMAL_CLOSURE || |
878 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && | 878 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && |
879 code < WebSocketStatus.RESERVED_1015) || | 879 code < WebSocketStatus.RESERVED_1015) || |
880 (code >= WebSocketStatus.RESERVED_1015 && | 880 (code >= WebSocketStatus.RESERVED_1015 && |
881 code < 3000)); | 881 code < 3000)); |
882 } | 882 } |
883 } | 883 } |
OLD | NEW |