From 553c913db02952f305e71e76aa0a8f6c71eb83ff Mon Sep 17 00:00:00 2001 From: glacambre Date: Sat, 30 Oct 2021 18:09:16 +0200 Subject: [PATCH] websocket server: send pong on ping Hopefully closes https://github.com/glacambre/firenvim/issues/1222. --- lua/firenvim-websocket.lua | 9 +++++++++ lua/firenvim.lua | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/firenvim-websocket.lua b/lua/firenvim-websocket.lua index 33a7f74a..4c14d146 100644 --- a/lua/firenvim-websocket.lua +++ b/lua/firenvim-websocket.lua @@ -137,6 +137,14 @@ local function encode_frame(data) return header .. len .. data end +local function pong_frame(decoded_frame) + -- 137: 10001010 + -- Fin: 1 + -- RSV{1,2,3}: 0 + -- Opcode: 0xA (pong) + return string.char(138) .. decoded_frame.payload_length .. decoded_frame.payload_data +end + local function close_frame() local frame = encode_frame("") return string.char(136) .. string.sub(frame, 2) @@ -149,4 +157,5 @@ return { encode_frame = encode_frame, opcodes = opcodes, parse_headers = parse_headers, + pong_frame = pong_frame, } diff --git a/lua/firenvim.lua b/lua/firenvim.lua index 720ab36d..300105ac 100644 --- a/lua/firenvim.lua +++ b/lua/firenvim.lua @@ -68,8 +68,7 @@ local function connection_handler(server, sock, token) current_payload = "" end elseif decoded_frame.opcode == websocket.opcodes.ping then - -- TODO: implement websocket.pong_frame - -- sock:write(websocket.pong_frame(decoded_frame)) + sock:write(websocket.pong_frame(decoded_frame)) return elseif decoded_frame.opcode == websocket.opcodes.close then sock:write(websocket.close_frame(decoded_frame))