Permalink
Browse files

http: Correct WebSocket close when code missing.

  • Loading branch information...
unknownbrackets committed Apr 13, 2018
1 parent 0fb15fc commit 403632b4ca44035167e54cf26d3bfc42b588f6fb
Showing with 12 additions and 7 deletions.
  1. +12 −7 ext/native/net/websocket_server.cpp
@@ -188,14 +188,19 @@ void WebSocketServer::Pong(const std::vector<uint8_t> &payload) {
void WebSocketServer::Close(WebSocketClose reason) {
closeReason_ = reason;
SendHeader(true, (int)Opcode::CLOSE, 2);
if (reason == WebSocketClose::NO_STATUS) {
// This means we received a CLOSE without a code.
SendHeader(true, (int)Opcode::CLOSE, 0);
} else {
SendHeader(true, (int)Opcode::CLOSE, 2);
uint16_t r = (uint16_t)reason;
uint8_t reasonData[] = {
(uint8_t)((r >> 8) & 0xFF),
(uint8_t)((r >> 0) & 0xFF),
};
SendBytes((const char *)reasonData, sizeof(reasonData));
uint16_t r = (uint16_t)reason;
uint8_t reasonData[] = {
(uint8_t)((r >> 8) & 0xFF),
(uint8_t)((r >> 0) & 0xFF),
};
SendBytes((const char *)reasonData, sizeof(reasonData));
}
sentClose_ = true;
}

0 comments on commit 403632b

Please sign in to comment.