From aa984e5ffcf9aa0679adc8bcb6d9bad15c6dfccb Mon Sep 17 00:00:00 2001 From: "ricea@chromium.org" Date: Wed, 26 Feb 2014 07:33:09 +0000 Subject: [PATCH] Allow sending of empty Close frames from Blink. net::WebSocketChannel provided no way for the renderer to send a Close frame with no payload. Allow the renderer to use code 1005 ("No Status Rcvd") to mean no payload should be sent. BUG=345683 TEST=net_unittests, layout test client-close.html Review URL: https://codereview.chromium.org/175213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253391 0039d316-1c4b-4281-b951-d872f2087c98 --- net/websockets/websocket_channel.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/websockets/websocket_channel.cc b/net/websockets/websocket_channel.cc index 84edecf4021c85..681ad7ee5ec816 100644 --- a/net/websockets/websocket_channel.cc +++ b/net/websockets/websocket_channel.cc @@ -55,12 +55,14 @@ const size_t kMaximumCloseReasonLength = 125 - kWebSocketCloseCodeLength; // used for close codes received from a renderer that we are intending to send // out over the network. See ParseClose() for the restrictions on incoming close // codes. The |code| parameter is type int for convenience of implementation; -// the real type is uint16. +// the real type is uint16. Code 1005 is treated specially; it cannot be set +// explicitly by Javascript but the renderer uses it to indicate we should send +// a Close frame with no payload. bool IsStrictlyValidCloseStatusCode(int code) { static const int kInvalidRanges[] = { // [BAD, OK) 0, 1000, // 1000 is the first valid code - 1005, 1007, // 1005 and 1006 MUST NOT be set. + 1006, 1007, // 1006 MUST NOT be set. 1014, 3000, // 1014 unassigned; 1015 up to 2999 are reserved. 5000, 65536, // Codes above 5000 are invalid. }; @@ -864,6 +866,7 @@ ChannelState WebSocketChannel::SendClose(uint16 code, if (code == kWebSocketErrorNoStatusReceived) { // Special case: translate kWebSocketErrorNoStatusReceived into a Close // frame with no payload. + DCHECK(reason.empty()); body = new IOBuffer(0); } else { const size_t payload_length = kWebSocketCloseCodeLength + reason.length();