diff options
author | Matthew Holt <[email protected]> | 2020-04-01 00:43:40 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2020-04-01 00:43:40 -0600 |
commit | 809e72792c501ceeadac4a3b9b327dfc575b9dfd (patch) | |
tree | a0cf16092fd3270430c9718974450495148f0cb1 /modules/caddyhttp/rewrite/rewrite_test.go | |
parent | 9fb0b1e838e216f90d20c9a32e948ad60dcca07d (diff) | |
download | caddy-809e72792c501ceeadac4a3b9b327dfc575b9dfd.tar.gz caddy-809e72792c501ceeadac4a3b9b327dfc575b9dfd.zip |
rewrite: Fix for rewrites with URI placeholders (#3209)
If a placeholder in the path component injects a query string such as
the {http.request.uri} placeholder is wont to do, we need to separate it
out from the path.
Diffstat (limited to 'modules/caddyhttp/rewrite/rewrite_test.go')
-rw-r--r-- | modules/caddyhttp/rewrite/rewrite_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/caddyhttp/rewrite/rewrite_test.go b/modules/caddyhttp/rewrite/rewrite_test.go index 34a0cdbde..fb4931b14 100644 --- a/modules/caddyhttp/rewrite/rewrite_test.go +++ b/modules/caddyhttp/rewrite/rewrite_test.go @@ -158,6 +158,36 @@ func TestRewrite(t *testing.T) { input: newRequest(t, "GET", "/foo/bar?a=b"), expect: newRequest(t, "GET", "/foo?a=b#frag"), }, + { + rule: Rewrite{URI: "/foo{http.request.uri}"}, + input: newRequest(t, "GET", "/bar?a=b"), + expect: newRequest(t, "GET", "/foo/bar?a=b"), + }, + { + rule: Rewrite{URI: "/foo{http.request.uri}"}, + input: newRequest(t, "GET", "/bar"), + expect: newRequest(t, "GET", "/foo/bar"), + }, + { + rule: Rewrite{URI: "/foo{http.request.uri}?c=d"}, + input: newRequest(t, "GET", "/bar?a=b"), + expect: newRequest(t, "GET", "/foo/bar?c=d"), + }, + { + rule: Rewrite{URI: "/foo{http.request.uri}?{http.request.uri.query}&c=d"}, + input: newRequest(t, "GET", "/bar?a=b"), + expect: newRequest(t, "GET", "/foo/bar?a=b&c=d"), + }, + { + rule: Rewrite{URI: "{http.request.uri}"}, + input: newRequest(t, "GET", "/bar?a=b"), + expect: newRequest(t, "GET", "/bar?a=b"), + }, + { + rule: Rewrite{URI: "{http.request.uri.path}bar?c=d"}, + input: newRequest(t, "GET", "/foo/?a=b"), + expect: newRequest(t, "GET", "/foo/bar?c=d"), + }, { rule: Rewrite{StripPathPrefix: "/prefix"}, @@ -211,6 +241,7 @@ func TestRewrite(t *testing.T) { } // populate the replacer just enough for our tests + repl.Set("http.request.uri", tc.input.RequestURI) repl.Set("http.request.uri.path", tc.input.URL.Path) repl.Set("http.request.uri.query", tc.input.URL.RawQuery) |