@@ -55,7 +55,18 @@ func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
5555 director := proxy.Director
5656 proxy.Director = func(req *http.Request) {
5757 director(req)
58− req.Host = target.Host
58+ // use RequestURI so that we aren't unescaping encoded slashes in the request path
59+ req.URL.Opaque = fmt.Sprintf("//%s%s", target.Host, req.RequestURI)
60+ req.URL.RawQuery = ""
61+ }
62+}
63+func setProxyDirector(proxy *httputil.ReverseProxy) {
64+ director := proxy.Director
65+ proxy.Director = func(req *http.Request) {
66+ director(req)
67+ // use RequestURI so that we aren't unescaping encoded slashes in the request path
68+ req.URL.Opaque = fmt.Sprintf("//%s%s", req.URL.Host, req.RequestURI)
69+ req.URL.RawQuery = ""
5970 }
6071}
6172
@@ -70,6 +81,8 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
7081 proxy := NewReverseProxy(u)
7182 if !opts.PassHostHeader {
7283 setProxyUpstreamHostHeader(proxy, u)
84+ } else {
85+ setProxyDirector(proxy)
7386 }
7487 serveMux.Handle(path, proxy)
7588 }