From fc65320e9c5b4e2ab96b6b421b65629560f1b8a2 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 17 Aug 2020 17:14:46 -0400 Subject: reverseproxy: Support header selection policy on `Host` field (#3653) --- modules/caddyhttp/reverseproxy/selectionpolicies.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/caddyhttp/reverseproxy/selectionpolicies.go') 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) -- cgit v1.2.3