Skip to content

Commit

Permalink
Added RawPath to HttpProxy. Issue fabiolb#486
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Spütz committed Jul 25, 2018
1 parent c1498bc commit a06f985
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions proxy/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions proxy/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a06f985

Please sign in to comment.