summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-08-17 17:14:46 -0400
committerGitHub <noreply@github.com>2020-08-17 15:14:46 -0600
commitfc65320e9c5b4e2ab96b6b421b65629560f1b8a2 (patch)
treee849fbf1a07e16af63ccea2994ff992e8fdea918 /modules/caddyhttp/reverseproxy
parente385be922569c07a0471a6798d4aeaf972facb5b (diff)
reverseproxy: Support header selection policy on `Host` field (#3653)
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-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 e33ebe4..343140f 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)