Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4849

How could I correctly fetch the request domain in Lua?

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 4849

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>