Skip to content

Commit

Permalink
Allow sending of empty Close frames from Blink.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ricea@chromium.org committed Feb 26, 2014
1 parent eedf562 commit aa984e5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/websockets/websocket_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit aa984e5

Please sign in to comment.