diff options
author | 2022-06-22 06:37:47 -0700 | |
---|---|---|
committer | 2022-06-22 06:56:47 -0700 | |
commit | d9f6a3f2d26750b5a1c6c3a10b0eab0f37a7c19c (patch) | |
tree | fa260a9b4675ff43b2efe9df265c7a2067adce6d | |
parent | 6db9e10ff1cb9a2a331be10a91c4919b2bd01732 (diff) | |
download | bun-d9f6a3f2d26750b5a1c6c3a10b0eab0f37a7c19c.tar.gz bun-d9f6a3f2d26750b5a1c6c3a10b0eab0f37a7c19c.tar.zst bun-d9f6a3f2d26750b5a1c6c3a10b0eab0f37a7c19c.zip |
Fix close
-rw-r--r-- | src/http/websocket_http_client.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/http/websocket_http_client.zig b/src/http/websocket_http_client.zig index 5dd81f6db..52d64b8a2 100644 --- a/src/http/websocket_http_client.zig +++ b/src/http/websocket_http_client.zig @@ -857,11 +857,14 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { } fn clearReceiveBuffers(this: *WebSocket, free: bool) void { - this.receive_buffer.discard(this.receive_buffer.count); + this.receive_buffer.head = 0; + this.receive_buffer.count = 0; + if (free) { this.receive_buffer.deinit(); this.receive_buffer.buf.len = 0; } + this.receive_pending_chunk_len = 0; this.receive_body_remain = 0; } @@ -891,7 +894,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { var outstring = JSC.ZigString.Empty; if (utf16_bytes_) |utf16| { outstring = JSC.ZigString.from16Slice(utf16); - outstring.markUTF16(); + outstring.mark(); JSC.markBinding(); WebSocket__didReceiveText(out, false, &outstring); } else { @@ -1118,7 +1121,13 @@ pub fn NewWebSocketClient(comptime ssl: bool) type { .close => { // closing frame data is text only. - _ = this.consume(data[0..receive_body_remain], receive_body_remain, .Text, true); + + // 2 byte close code + if (data.len > 2) { + _ = this.consume(data[2..receive_body_remain], receive_body_remain - 2, .Text, true); + data = data[receive_body_remain..]; + } + this.sendClose(); terminated = true; break; |