mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-29 23:25:50 +08:00
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:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user