Skip to content

Commit

Permalink
Use the raw url path when proxying upstream requests
Browse files Browse the repository at this point in the history
This way escaped char's like /%2F/ will still work instead of returning
301. The proxy should ideally touch the request as little as possible /
needed.
  • Loading branch information
FStelzer committed Jan 18, 2021
1 parent 9c126f5 commit 56b8a83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/upstream/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type multiUpstreamProxy struct {

// ServerHTTP handles HTTP requests.
func (m *multiUpstreamProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
req.URL.Path = req.URL.EscapedPath()
m.serveMux.ServeHTTP(rw, req)
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/upstream/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,16 @@ var _ = Describe("Proxy Suite", func() {
raw: "404 page not found\n",
},
}),
Entry("with a request to a path containing an escaped '/' in its name", &proxyTableInput{
target: "http://example.localhost/%2F/",
response: testHTTPResponse{
code: 404, // Default http mux will rewrite this with an 301
header: map[string][]string{
"X-Content-Type-Options": {"nosniff"},
contentType: {textPlainUTF8},
},
raw: "404 page not found\n",
},
}),
)
})

0 comments on commit 56b8a83

Please sign in to comment.