From 1a1d8abd2ebdbc592d5d407c9133afb9a4a76f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E4=BA=91?= Date: Mon, 17 Oct 2022 19:29:33 +0800 Subject: [PATCH] read 'x-real-ip' header from nginx in websocket lib. (#1665) * read 'x-real-ip' header from nginx in websocket lib. * change default real_ip value to nil --- lualib/http/websocket.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lualib/http/websocket.lua b/lualib/http/websocket.lua index f09b826f..a7e62ea7 100755 --- a/lualib/http/websocket.lua +++ b/lualib/http/websocket.lua @@ -139,6 +139,9 @@ local function read_handshake(self, upgrade_ops) end end + -- read 'x-real-ip' header from nginx + self.real_ip = header["x-real-ip"] + -- response handshake local accept = crypt.base64encode(crypt.sha1(sw_key .. self.guid)) local resp = "HTTP/1.1 101 Switching Protocols\r\n".. @@ -497,6 +500,11 @@ function M.addrinfo(id) return ws_obj.addr end +function M.real_ip(id) + local ws_obj = assert(ws_pool[id]) + return ws_obj.real_ip +end + function M.close(id, code ,reason) local ws_obj = ws_pool[id] if not ws_obj then