I need to fetch the HTTP request’s domain to perform domain whitelist verification, but sometimes I cannot retrieve the host value—it returns nil. My HAProxy version is 3.1.5, and I’m using the following Lua script to get the host:
function get_host(txn)
local sni = txn.sf:ssl_fc_sni()
-- HTTP request Host header
local host = txn.sf:req_fhdr("Host")
-- In some cases (HTTP/2), domain is in :authority
if (not host or host == "") then
host = txn.sf:req_fhdr(":authority")
end
local domain = host or sni
return domain
end
However, when I use the log-format to print the request-line with %{+Q}r, it does have a value. Could anyone provide a complete working code example?
Thank you!
1 post - 1 participant