From 1c223d993157d86a3a4e41857910f75e264218b0 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Tue, 28 Nov 2017 01:37:26 -0500 Subject: [PATCH] Allow setting upstream Host header --- forwarding.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/forwarding.go b/forwarding.go index e7669fff..6851a10a 100644 --- a/forwarding.go +++ b/forwarding.go @@ -58,7 +58,12 @@ func (r *oauthProxy) proxyMiddleware(next http.Handler) http.Handler { // and we must update the host headers req.URL.Host = r.endpoint.Host req.URL.Scheme = r.endpoint.Scheme - req.Host = r.endpoint.Host + if v := req.Header.Get("Host"); v != "" { + req.Host = v + req.Header.Del("Host") + } else { + req.Host = r.endpoint.Host + } req.Header.Add("X-Forwarded-For", realIP(req)) req.Header.Set("X-Forwarded-Host", req.URL.Host)