proxyprotocol: Add PROXY protocol support to reverse_proxy, add HTTP listener wrapper (#5424)

Co-authored-by: WeidiDeng <weidi_deng@icloud.com>
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
Corin Langosch
2023-03-31 23:44:53 +02:00
committed by GitHub
parent 66e571e687
commit b6fe5d4b41
9 changed files with 245 additions and 1 deletions

View File

@ -688,8 +688,18 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
req.Header.Set("Upgrade", reqUpType)
}
// Set up the PROXY protocol info
address := caddyhttp.GetVar(req.Context(), caddyhttp.ClientIPVarKey).(string)
addrPort, err := netip.ParseAddrPort(address)
if err != nil {
// OK; probably didn't have a port
addrPort, _ = netip.ParseAddrPort(address + ":0")
}
proxyProtocolInfo := ProxyProtocolInfo{AddrPort: addrPort}
caddyhttp.SetVar(req.Context(), proxyProtocolInfoVarKey, proxyProtocolInfo)
// Add the supported X-Forwarded-* headers
err := h.addForwardedHeaders(req)
err = h.addForwardedHeaders(req)
if err != nil {
return nil, err
}