From 48c9a60d193c6c329a5d2b8681bd4b914f03af71 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 23 Jun 2020 15:39:31 +0200 Subject: net.http.server: Strip port from Host header in IPv6 friendly way (fix #1302) E.g. given `[::1]:5280` it would previously result in only `[` instead of the correct `[::1]` --- net/http/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net') diff --git a/net/http/server.lua b/net/http/server.lua index 9b63d516..d0bd3294 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -207,7 +207,7 @@ function handle_request(conn, request, finish_cb) }; conn._http_open_response = response; - local host = (request.headers.host or ""):match("[^:]+"); + local host = (request.headers.host or ""):gsub(":%d+$",""); -- Some sanity checking local err_code, err; -- cgit v1.2.3 From 540be50a3c3165d08e7e98d406dd911122d51941 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 23 Jun 2020 15:43:57 +0200 Subject: net.http.server: Fix reporting of missing Host header The "Missing or invalid 'Host' header" case was dead code previously because `host` was always at least an empty string. --- net/http/server.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/http/server.lua b/net/http/server.lua index d0bd3294..18704962 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -207,7 +207,8 @@ function handle_request(conn, request, finish_cb) }; conn._http_open_response = response; - local host = (request.headers.host or ""):gsub(":%d+$",""); + local host = request.headers.host; + if host then host = host:gsub(":%d+$",""); end -- Some sanity checking local err_code, err; -- cgit v1.2.3