mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
Merge pull request #5076 from caddyserver/fastcgi-redir
fastcgi: Redirect using original URI path (fix #5073) and rewrite: Only trim prefix if matched
This commit is contained in:
commit
897a38958c
8 changed files with 24 additions and 9 deletions
|
@ -8,7 +8,7 @@ route {
|
|||
}
|
||||
not path */
|
||||
}
|
||||
redir @canonicalPath {path}/ 308
|
||||
redir @canonicalPath {http.request.orig_uri.path}/ 308
|
||||
|
||||
# If the requested file does not exist, try index files
|
||||
@indexFiles {
|
||||
|
@ -50,7 +50,7 @@ route {
|
|||
"handler": "static_response",
|
||||
"headers": {
|
||||
"Location": [
|
||||
"{http.request.uri.path}/"
|
||||
"{http.request.orig_uri.path}/"
|
||||
]
|
||||
},
|
||||
"status_code": 308
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
"handler": "static_response",
|
||||
"headers": {
|
||||
"Location": [
|
||||
"{http.request.uri.path}/"
|
||||
"{http.request.orig_uri.path}/"
|
||||
]
|
||||
},
|
||||
"status_code": 308
|
||||
|
|
|
@ -30,7 +30,7 @@ php_fastcgi @api localhost:9000
|
|||
"handler": "static_response",
|
||||
"headers": {
|
||||
"Location": [
|
||||
"{http.request.uri.path}/"
|
||||
"{http.request.orig_uri.path}/"
|
||||
]
|
||||
},
|
||||
"status_code": 308
|
||||
|
|
|
@ -43,7 +43,7 @@ php_fastcgi localhost:9000 {
|
|||
"handler": "static_response",
|
||||
"headers": {
|
||||
"Location": [
|
||||
"{http.request.uri.path}/"
|
||||
"{http.request.orig_uri.path}/"
|
||||
]
|
||||
},
|
||||
"status_code": 308
|
||||
|
|
|
@ -46,7 +46,7 @@ php_fastcgi localhost:9000 {
|
|||
"handler": "static_response",
|
||||
"headers": {
|
||||
"Location": [
|
||||
"{http.request.uri.path}/"
|
||||
"{http.request.orig_uri.path}/"
|
||||
]
|
||||
},
|
||||
"status_code": 308
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -383,10 +383,15 @@ func trimPathPrefix(escapedPath, prefix string) string {
|
|||
iPrefix++
|
||||
}
|
||||
|
||||
// found matching prefix, trim it
|
||||
// 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 {
|
||||
r := []rune(s)
|
||||
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
|
||||
|
|
|
@ -225,6 +225,16 @@ func TestRewrite(t *testing.T) {
|
|||
input: newRequest(t, "GET", "/prefix/foo/bar"),
|
||||
expect: newRequest(t, "GET", "/foo/bar"),
|
||||
},
|
||||
{
|
||||
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"),
|
||||
|
|
Loading…
Reference in a new issue