Skip to content

Commit add3c23

Browse files
committed
net/websocket: Send close when we receive close
Per specification
1 parent ef73289 commit add3c23

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/net/http/http.c

+9
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ websocket_parser_execute(http_connection_t *hc,
386386
int result = hc->hc_ws_cb(hc->hc_ws_opaque, hc->hc_ws_rx_opcode,
387387
ba->data, ba->used, hc, ba);
388388

389+
if(hc->hc_ws_rx_opcode == WS_OPCODE_CLOSE && result == 0) {
390+
if(ba->used > 2) {
391+
const uint8_t *u8 = ba->data;
392+
result = (u8[0] << 8) | u8[1];
393+
} else {
394+
result = WS_STATUS_NORMAL_CLOSE;
395+
}
396+
}
397+
389398
if(result) {
390399
// Returned error code, Close connection
391400
uint8_t payload[2] = {result >> 8, result};

0 commit comments

Comments
 (0)