Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
reverseproxy: always set req.URL.Host with upstream (#3297)
westwin committed
Apr 22, 2020 at 10:34 UTC
da8686c4b974ba0b35f3be5a43b6a2f3a528fed2
1 file changed
+9
-11
modules/caddyhttp/reverseproxy/reverseproxy.go
+9
-11
@@ -613,19 +613,17 @@ func (lb LoadBalancing) tryAgain(start time.Time, proxyErr error, req *http.Requ
613
// directRequest modifies only req.URL so that it points to the upstream
614
// in the given DialInfo. It must modify ONLY the request URL.
615
func (h Handler) directRequest(req *http.Request, di DialInfo) {
616
- if req.URL.Host == "" {
617
- // we need a host, so set the upstream's host address
618
- reqHost := di.Address
619
-
620
- // if the port equates to the scheme, strip the port because
621
- // it's weird to make a request like http://example.com:80/.
622
- if (req.URL.Scheme == "http" && di.Port == "80") ||
623
- (req.URL.Scheme == "https" && di.Port == "443") {
624
- reqHost = di.Host
625
- }
616
+ // we need a host, so set the upstream's host address
617
+ reqHost := di.Address
618
627
- req.URL.Host = reqHost
619
+ // if the port equates to the scheme, strip the port because
620
+ // it's weird to make a request like http://example.com:80/.
621
+ if (req.URL.Scheme == "http" && di.Port == "80") ||
622
+ (req.URL.Scheme == "https" && di.Port == "443") {
623
+ reqHost = di.Host
624
}
625
+
626
+ req.URL.Host = reqHost
627
}
628
629
// shouldPanicOnCopyError reports whether the reverse proxy should