Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 14:45 UTC
reverseproxy: query escape request urls when proxy protocol is enabled (#7537)
WeidiDeng committed
Mar 2, 2026 at 15:04 UTC
2ab043b8903db4574b2fc7a625619018a072f082
1 file changed
+6
-1
modules/caddyhttp/reverseproxy/reverseproxy.go
+6
-1
@@ -1278,7 +1278,12 @@ func (h *Handler) directRequest(req *http.Request, di DialInfo) {
1278
// add client address to the host to let transport differentiate requests from different clients
1279
if ppt, ok := h.Transport.(ProxyProtocolTransport); ok && ppt.ProxyProtocolEnabled() {
1280
if proxyProtocolInfo, ok := caddyhttp.GetVar(req.Context(), proxyProtocolInfoVarKey).(ProxyProtocolInfo); ok {
1281
- reqHost = proxyProtocolInfo.AddrPort.String() + "->" + reqHost
1281
+ // encode the request so it plays well with h2 transport, it's unnecessary for h1 but anyway
1282
+ // The issue is that h2 transport will use the address to determine if new connections are needed
1283
+ // to roundtrip requests but the without escaping, new connections are constantly created and closed until
1284
+ // file descriptors are exhausted.
1285
+ // see: https://github.com/caddyserver/caddy/issues/7529
1286
+ reqHost = url.QueryEscape(proxyProtocolInfo.AddrPort.String() + "->" + reqHost)
1287
}
1288
}
1289