summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/reverseproxy.go
diff options
context:
space:
mode:
authorCorin Langosch <info@corinlangosch.com>2023-03-31 23:44:53 +0200
committerGitHub <noreply@github.com>2023-03-31 17:44:53 -0400
commitb6fe5d4b41d07e70a502ed58d40e8b0e75067db5 (patch)
tree5be3fd6968105029b9c28c7e9c4c8d3a806dcbf4 /modules/caddyhttp/reverseproxy/reverseproxy.go
parent66e571e687eeddca0aafd5df0e3ab5f7cecbdcfa (diff)
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>
Diffstat (limited to 'modules/caddyhttp/reverseproxy/reverseproxy.go')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 8fd24fe..ff22d49 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -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
}