summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorwestwin <westwin@gmail.com>2020-04-22 10:34:00 +0800
committerGitHub <noreply@github.com>2020-04-21 20:34:00 -0600
commitda8686c4b974ba0b35f3be5a43b6a2f3a528fed2 (patch)
treeb6662630b142fdf4344a5e1139bf8a9680830eef /modules
parente3a8f72f1c090368364eac851a6e05b9339c86ad (diff)
reverseproxy: always set req.URL.Host with upstream (#3297)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 2f871da..e322a74 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -613,19 +613,17 @@ func (lb LoadBalancing) tryAgain(start time.Time, proxyErr error, req *http.Requ
// directRequest modifies only req.URL so that it points to the upstream
// in the given DialInfo. It must modify ONLY the request URL.
func (h Handler) directRequest(req *http.Request, di DialInfo) {
- if req.URL.Host == "" {
- // we need a host, so set the upstream's host address
- reqHost := di.Address
-
- // if the port equates to the scheme, strip the port because
- // it's weird to make a request like http://example.com:80/.
- if (req.URL.Scheme == "http" && di.Port == "80") ||
- (req.URL.Scheme == "https" && di.Port == "443") {
- reqHost = di.Host
- }
+ // we need a host, so set the upstream's host address
+ reqHost := di.Address
- req.URL.Host = reqHost
+ // if the port equates to the scheme, strip the port because
+ // it's weird to make a request like http://example.com:80/.
+ if (req.URL.Scheme == "http" && di.Port == "80") ||
+ (req.URL.Scheme == "https" && di.Port == "443") {
+ reqHost = di.Host
}
+
+ req.URL.Host = reqHost
}
// shouldPanicOnCopyError reports whether the reverse proxy should