fastcgi: Set PATH_INFO to file matcher remainder as fallback (#3739)

* fastcgi: Set PATH_INFO to file matcher remainder as fallback

* fastcgi: Avoid changing scriptName when not necessary

* Stylistic tweaks

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
This commit is contained in:
Francis Lavoie 2020-12-04 19:12:13 -05:00 committed by GitHub
parent 5643dc3fb9
commit 6e9ac248dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 29 deletions

View file

@ -195,19 +195,27 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
}
fpath := r.URL.Path
scriptName := fpath
docURI := fpath
// split "actual path" from "path info" if configured
var docURI, pathInfo string
var pathInfo string
if splitPos := t.splitPos(fpath); splitPos > -1 {
docURI = fpath[:splitPos]
pathInfo = fpath[splitPos:]
} else {
docURI = fpath
}
scriptName := fpath
// Strip PATH_INFO from SCRIPT_NAME
scriptName = strings.TrimSuffix(scriptName, pathInfo)
// Strip PATH_INFO from SCRIPT_NAME
scriptName = strings.TrimSuffix(scriptName, pathInfo)
}
// Try to grab the path remainder from a file matcher
// if we didn't get a split result here.
// See https://github.com/caddyserver/caddy/issues/3718
if pathInfo == "" {
if remainder, ok := repl.GetString("http.matchers.file.remainder"); ok {
pathInfo = remainder
}
}
// SCRIPT_FILENAME is the absolute path of SCRIPT_NAME
scriptFilename := filepath.Join(root, scriptName)