net.http.server: Set request.ip so mod_http doesn't have to

Because it already sets request.secure, which depends on the connection,
just like the IP, so it makes sense to do both in the same place.

Dealing with proxies can be left to mod_http for now, but maybe it could
move into some util some day?
This commit is contained in:
Kim Alvefur 2021-02-27 21:37:16 +01:00
parent d8bcee69f3
commit 2acba62388
2 changed files with 3 additions and 1 deletions

View file

@ -113,6 +113,7 @@ local function noop() end
function listener.onconnect(conn) function listener.onconnect(conn)
local session = { conn = conn }; local session = { conn = conn };
local secure = conn:ssl() and true or nil; local secure = conn:ssl() and true or nil;
local ip = conn:ip();
session.thread = async.runner(function (request) session.thread = async.runner(function (request)
local wait, done; local wait, done;
if request.partial == true then if request.partial == true then
@ -127,6 +128,7 @@ function listener.onconnect(conn)
end, runner_callbacks, session); end, runner_callbacks, session);
local function success_cb(request) local function success_cb(request)
--log("debug", "success_cb: %s", request.path); --log("debug", "success_cb: %s", request.path);
request.ip = ip;
request.secure = secure; request.secure = secure;
session.thread:run(request); session.thread:run(request);
end end

View file

@ -260,7 +260,7 @@ local function is_trusted_proxy(ip)
end end
local function get_ip_from_request(request) local function get_ip_from_request(request)
local ip = request.conn:ip(); local ip = request.ip;
local forwarded_for = request.headers.x_forwarded_for; local forwarded_for = request.headers.x_forwarded_for;
if forwarded_for and is_trusted_proxy(ip) then if forwarded_for and is_trusted_proxy(ip) then
-- luacheck: ignore 631 -- luacheck: ignore 631