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