From a06f98503d063e88b123176296f79a03bf0bf3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sp=C3=BCtz?= Date: Wed, 25 Jul 2018 08:38:54 +0200 Subject: [PATCH] Added RawPath to HttpProxy. Issue #486 --- proxy/http_handler.go | 1 + proxy/http_proxy.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/proxy/http_handler.go b/proxy/http_handler.go index cfde275eb..18cae7f90 100644 --- a/proxy/http_handler.go +++ b/proxy/http_handler.go @@ -17,6 +17,7 @@ func newHTTPProxy(target *url.URL, tr http.RoundTripper, flush time.Duration) ht req.URL.Scheme = target.Scheme req.URL.Host = target.Host req.URL.Path = target.Path + req.URL.RawPath = target.RawPath req.URL.RawQuery = target.RawQuery if _, ok := req.Header["User-Agent"]; !ok { // explicitly disable User-Agent so it's not set to default value diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index a4415d573..cc86a5666 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -96,6 +96,7 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { Scheme: scheme(r), Host: r.Host, Path: r.URL.Path, + RawPath: r.URL.RawPath, RawQuery: r.URL.RawQuery, } @@ -113,6 +114,7 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { Scheme: t.URL.Scheme, Host: t.URL.Host, Path: r.URL.Path, + RawPath: r.URL.RawPath, } if t.URL.RawQuery == "" || r.URL.RawQuery == "" { targetURL.RawQuery = t.URL.RawQuery + r.URL.RawQuery @@ -133,6 +135,9 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { if t.StripPath != "" && strings.HasPrefix(r.URL.Path, t.StripPath) { targetURL.Path = targetURL.Path[len(t.StripPath):] } + if t.StripPath != "" && strings.HasPrefix(r.URL.RawPath, t.StripPath) { + targetURL.RawPath = targetURL.RawPath[len(t.StripPath):] + } if err := addHeaders(r, p.Config, t.StripPath); err != nil { http.Error(w, "cannot parse "+r.RemoteAddr, http.StatusInternalServerError)