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
This commit is contained in:
子云
2022-10-17 19:29:33 +08:00
committed by GitHub
parent feeda06e9d
commit 1a1d8abd2e

View File

@@ -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