Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: runtime/bin/websocket_impl.dart

Issue 10946007: Never send reserved status codes in a close frame (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 5 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
6 6
7 class _WebSocketMessageType { 7 class _WebSocketMessageType {
8 static const int NONE = 0; 8 static const int NONE = 0;
9 static const int BINARY = 1; 9 static const int BINARY = 1;
10 static const int TEXT = 2; 10 static const int TEXT = 2;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 void _controlFrameEnd() { 282 void _controlFrameEnd() {
283 switch (_opcode) { 283 switch (_opcode) {
284 case _WebSocketOpcode.CLOSE: 284 case _WebSocketOpcode.CLOSE:
285 int status = WebSocketStatus.NO_STATUS_RECEIVED; 285 int status = WebSocketStatus.NO_STATUS_RECEIVED;
286 String reason = ""; 286 String reason = "";
287 if (_controlPayload.length > 0) { 287 if (_controlPayload.length > 0) {
288 if (_controlPayload.length == 1) { 288 if (_controlPayload.length == 1) {
289 throw new WebSocketException("Protocol error"); 289 throw new WebSocketException("Protocol error");
290 } 290 }
291 status = _controlPayload[0] << 8 | _controlPayload[1]; 291 status = _controlPayload[0] << 8 | _controlPayload[1];
292 if (status == WebSocketStatus.NO_STATUS_RECEIVED) {
293 throw new WebSocketException("Protocol error");
294 }
292 if (_controlPayload.length > 2) { 295 if (_controlPayload.length > 2) {
293 var decoder = _StringDecoders.decoder(Encoding.UTF_8); 296 var decoder = _StringDecoders.decoder(Encoding.UTF_8);
294 decoder.write( 297 decoder.write(
295 _controlPayload.getRange(2, _controlPayload.length - 2)); 298 _controlPayload.getRange(2, _controlPayload.length - 2));
296 reason = decoder.decoded(); 299 reason = decoder.decoded();
297 } 300 }
298 } 301 }
299 if (onClosed !== null) onClosed(status, reason); 302 if (onClosed !== null) onClosed(status, reason);
300 _state = CLOSED; 303 _state = CLOSED;
301 break; 304 break;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 opcode = _WebSocketOpcode.BINARY; 419 opcode = _WebSocketOpcode.BINARY;
417 data = message; 420 data = message;
418 } 421 }
419 } else { 422 } else {
420 opcode = _WebSocketOpcode.TEXT; 423 opcode = _WebSocketOpcode.TEXT;
421 } 424 }
422 _sendFrame(opcode, data); 425 _sendFrame(opcode, data);
423 } 426 }
424 427
425 close([int status, String reason]) { 428 close([int status, String reason]) {
429 if (status == WebSocketStatus.RESERVED_1004 ||
430 status == WebSocketStatus.NO_STATUS_RECEIVED ||
431 status == WebSocketStatus.RESERVED_1015) {
432 throw new WebSocketException("Reserved status code $status");
433 }
434
426 if (_closeSent) return; 435 if (_closeSent) return;
427 List<int> data; 436 List<int> data;
428 if (status !== null) { 437 if (status !== null) {
429 data = new List<int>(); 438 data = new List<int>();
430 data.add((status >> 8) & 0xFF); 439 data.add((status >> 8) & 0xFF);
431 data.add(status & 0xFF); 440 data.add(status & 0xFF);
432 if (reason !== null) { 441 if (reason !== null) {
433 data.addAll( 442 data.addAll(
434 _StringEncoders.encoder(Encoding.UTF_8).encodeString(reason)); 443 _StringEncoders.encoder(Encoding.UTF_8).encodeString(reason));
435 } 444 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 508 }
500 509
501 _onWebSocketClosed(int status, String reason) { 510 _onWebSocketClosed(int status, String reason) {
502 _closeReceived = true; 511 _closeReceived = true;
503 if (_onClosed !== null) _onClosed(status, reason); 512 if (_onClosed !== null) _onClosed(status, reason);
504 if (_closeSent) { 513 if (_closeSent) {
505 // Got close frame in response to close frame. Now close the socket. 514 // Got close frame in response to close frame. Now close the socket.
506 if (_closeTimer !== null) _closeTimer.cancel(); 515 if (_closeTimer !== null) _closeTimer.cancel();
507 _socket.close(); 516 _socket.close();
508 } else { 517 } else {
509 close(status); 518 if (status != WebSocketStatus.NO_STATUS_RECEIVED) {
519 close(status);
520 } else {
521 close();
522 }
510 } 523 }
511 } 524 }
512 525
513 _sendFrame(int opcode, [List<int> data]) { 526 _sendFrame(int opcode, [List<int> data]) {
514 bool mask = false; // Masking not implemented for server. 527 bool mask = false; // Masking not implemented for server.
515 int dataLength = data == null ? 0 : data.length; 528 int dataLength = data == null ? 0 : data.length;
516 // Determine the header size. 529 // Determine the header size.
517 int headerSize = (mask) ? 6 : 2; 530 int headerSize = (mask) ? 6 : 2;
518 if (dataLength > 65535) { 531 if (dataLength > 65535) {
519 headerSize += 8; 532 headerSize += 8;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 864
852 class _WebSocketCloseEvent implements CloseEvent { 865 class _WebSocketCloseEvent implements CloseEvent {
853 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); 866 _WebSocketCloseEvent(this._wasClean, this._code, this._reason);
854 bool get wasClean => _wasClean; 867 bool get wasClean => _wasClean;
855 int get code => _code; 868 int get code => _code;
856 String get reason => _reason; 869 String get reason => _reason;
857 bool _wasClean; 870 bool _wasClean;
858 int _code; 871 int _code;
859 String _reason; 872 String _reason;
860 } 873 }
OLDNEW
« no previous file with comments | « runtime/bin/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698