Skip to content

Commit 2ab043b

Browse files
authored
reverseproxy: query escape request urls when proxy protocol is enabled (#7537)
1 parent f145bce commit 2ab043b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

modules/caddyhttp/reverseproxy/reverseproxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,12 @@ func (h *Handler) directRequest(req *http.Request, di DialInfo) {
12781278
// add client address to the host to let transport differentiate requests from different clients
12791279
if ppt, ok := h.Transport.(ProxyProtocolTransport); ok && ppt.ProxyProtocolEnabled() {
12801280
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)
12821287
}
12831288
}
12841289

0 commit comments

Comments
 (0)