diff options
author | Francis Lavoie <[email protected]> | 2020-08-17 17:14:46 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-17 15:14:46 -0600 |
commit | fc65320e9c5b4e2ab96b6b421b65629560f1b8a2 (patch) | |
tree | e849fbf1a07e16af63ccea2994ff992e8fdea918 /modules/caddyhttp/reverseproxy/selectionpolicies.go | |
parent | e385be922569c07a0471a6798d4aeaf972facb5b (diff) | |
download | caddy-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.go | 7 |
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) |