summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2022-09-28 15:22:45 -0600
committerGitHub <noreply@github.com>2022-09-28 15:22:45 -0600
commit897a38958cb733551339f40f04e5798fcda55bcc (patch)
tree1f15a03c5d6f50a4fce046822c65d1c0ee23dfa5 /modules/caddyhttp
parent61822f129b9edbbc1ed2fd068d8e5ba919b5881d (diff)
parent013b5103527cb1646dc717cadf48ad34aceaa77e (diff)
Merge pull request #5076 from caddyserver/fastcgi-redir
fastcgi: Redirect using original URI path (fix #5073) and rewrite: Only trim prefix if matched
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go2
-rw-r--r--modules/caddyhttp/rewrite/rewrite.go9
-rw-r--r--modules/caddyhttp/rewrite/rewrite_test.go10
3 files changed, 18 insertions, 3 deletions
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
index a9e6b22..799050e 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
@@ -348,7 +348,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
}
redirHandler := caddyhttp.StaticResponse{
StatusCode: caddyhttp.WeakString(strconv.Itoa(http.StatusPermanentRedirect)),
- Headers: http.Header{"Location": []string{"{http.request.uri.path}/"}},
+ Headers: http.Header{"Location": []string{"{http.request.orig_uri.path}/"}},
}
redirRoute := caddyhttp.Route{
MatcherSetsRaw: []caddy.ModuleMap{redirMatcherSet},
diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go
index 95bc504..31c9778 100644
--- a/modules/caddyhttp/rewrite/rewrite.go
+++ b/modules/caddyhttp/rewrite/rewrite.go
@@ -383,8 +383,13 @@ func trimPathPrefix(escapedPath, prefix string) string {
iPrefix++
}
- // found matching prefix, trim it
- return escapedPath[iPath:]
+ // if we iterated through the entire prefix, we found it, so trim it
+ if iPath >= len(prefix) {
+ return escapedPath[iPath:]
+ }
+
+ // otherwise we did not find the prefix
+ return escapedPath
}
func reverse(s string) string {
diff --git a/modules/caddyhttp/rewrite/rewrite_test.go b/modules/caddyhttp/rewrite/rewrite_test.go
index bc20c85..5875983 100644
--- a/modules/caddyhttp/rewrite/rewrite_test.go
+++ b/modules/caddyhttp/rewrite/rewrite_test.go
@@ -227,6 +227,16 @@ func TestRewrite(t *testing.T) {
},
{
rule: Rewrite{StripPathPrefix: "/prefix"},
+ input: newRequest(t, "GET", "/prefix"),
+ expect: newRequest(t, "GET", ""),
+ },
+ {
+ rule: Rewrite{StripPathPrefix: "/prefix"},
+ input: newRequest(t, "GET", "/"),
+ expect: newRequest(t, "GET", "/"),
+ },
+ {
+ rule: Rewrite{StripPathPrefix: "/prefix"},
input: newRequest(t, "GET", "/prefix/foo%2Fbar"),
expect: newRequest(t, "GET", "/foo%2Fbar"),
},