Skip to content

Commit

Permalink
fix: strip path from incoming request, not the upstream request
Browse files Browse the repository at this point in the history
  • Loading branch information
fenech committed Feb 29, 2024
1 parent 817943a commit 8dc4fa4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func ConfigureBackendURL(r *http.Request, rl *rule.Rule) error {

if rl.Upstream.StripPath != "" {
forwardURL.Path = strings.Replace(forwardURL.Path, "/"+strings.Trim(rl.Upstream.StripPath, "/"), "", 1)
proxyPath = strings.Replace(proxyPath, "/"+strings.Trim(rl.Upstream.StripPath, "/"), "", 1)
}
forwardURL.Path = "/" + strings.TrimLeft("/"+strings.Trim(backendPath, "/")+"/"+strings.TrimLeft(proxyPath, "/"), "/")

r.Host = backendHost
if rl.Upstream.PreserveHost {
Expand Down
6 changes: 6 additions & 0 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ func TestConfigureBackendURL(t *testing.T) {
eURL: "http://localhost:4000/foo/users/1234",
eHost: "localhost:3000",
},
{
r: &http.Request{Host: "localhost:3000", URL: &url.URL{Path: "/foo/baz", Scheme: "http"}},
rl: &rule.Rule{Upstream: rule.Upstream{URL: "http://localhost:4000/foo/bar", PreserveHost: true, StripPath: "foo"}},
eURL: "http://localhost:4000/foo/bar/baz",
eHost: "localhost:3000",
},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
require.NoError(t, proxy.ConfigureBackendURL(tc.r, tc.rl))
Expand Down

0 comments on commit 8dc4fa4

Please sign in to comment.