aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/reverseproxy/selectionpolicies.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2020-08-17 17:14:46 -0400
committerGitHub <[email protected]>2020-08-17 15:14:46 -0600
commitfc65320e9c5b4e2ab96b6b421b65629560f1b8a2 (patch)
treee849fbf1a07e16af63ccea2994ff992e8fdea918 /modules/caddyhttp/reverseproxy/selectionpolicies.go
parente385be922569c07a0471a6798d4aeaf972facb5b (diff)
downloadcaddy-fc65320e9c5b4e2ab96b6b421b65629560f1b8a2.tar.gz
caddy-fc65320e9c5b4e2ab96b6b421b65629560f1b8a2.zip
reverseproxy: Support header selection policy on `Host` field (#3653)
Diffstat (limited to 'modules/caddyhttp/reverseproxy/selectionpolicies.go')
-rw-r--r--modules/caddyhttp/reverseproxy/selectionpolicies.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go
index e33ebe476..343140fc1 100644
--- a/modules/caddyhttp/reverseproxy/selectionpolicies.go
+++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go
@@ -362,6 +362,13 @@ func (s HeaderHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstr
if s.Field == "" {
return nil
}
+
+ // The Host header should be obtained from the req.Host field
+ // since net/http removes it from the header map.
+ if s.Field == "Host" && req.Host != "" {
+ return hostByHashing(pool, req.Host)
+ }
+
val := req.Header.Get(s.Field)
if val == "" {
return RandomSelection{}.Select(pool, req)