mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 15:53:17 +00:00
only add client address if proxy protocol is enabled
This commit is contained in:
parent
a5e910d519
commit
a64931b84e
1 changed files with 5 additions and 3 deletions
|
@ -1194,7 +1194,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int
|
||||||
|
|
||||||
// directRequest modifies only req.URL so that it points to the upstream
|
// directRequest modifies only req.URL so that it points to the upstream
|
||||||
// in the given DialInfo. It must modify ONLY the request URL.
|
// in the given DialInfo. It must modify ONLY the request URL.
|
||||||
func (Handler) directRequest(req *http.Request, di DialInfo) {
|
func (h *Handler) directRequest(req *http.Request, di DialInfo) {
|
||||||
// we need a host, so set the upstream's host address
|
// we need a host, so set the upstream's host address
|
||||||
reqHost := di.Address
|
reqHost := di.Address
|
||||||
|
|
||||||
|
@ -1206,8 +1206,10 @@ func (Handler) directRequest(req *http.Request, di DialInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add client address to the host to let transport differentiate requests from different clients
|
// add client address to the host to let transport differentiate requests from different clients
|
||||||
if proxyProtocolInfo, ok := caddyhttp.GetVar(req.Context(), proxyProtocolInfoVarKey).(ProxyProtocolInfo); ok {
|
if ht, ok := h.Transport.(*HTTPTransport); ok && ht.ProxyProtocol != "" {
|
||||||
reqHost = proxyProtocolInfo.AddrPort.String() + "->" + reqHost
|
if proxyProtocolInfo, ok := caddyhttp.GetVar(req.Context(), proxyProtocolInfoVarKey).(ProxyProtocolInfo); ok {
|
||||||
|
reqHost = proxyProtocolInfo.AddrPort.String() + "->" + reqHost
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.URL.Host = reqHost
|
req.URL.Host = reqHost
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue