From 0d91a36203278f3449984b8141c0f0e96bb9cff9 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Tue, 22 Sep 2020 21:46:34 -0400 Subject: [PATCH] fastcgi: Avoid changing scriptName when not necessary --- .../caddyhttp/reverseproxy/fastcgi/fastcgi.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go index 55c0c4c374d5..96950af07a43 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go @@ -195,19 +195,21 @@ 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 + + // Strip PATH_INFO from SCRIPT_NAME + scriptName = strings.TrimSuffix(scriptName, pathInfo) } - scriptName := fpath - // Try to grab the path remainder from a file matcher if we didn't - // get a split result here. + // 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.Get("http.matchers.file.remainder"); ok { @@ -215,9 +217,6 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) { } } - // Strip PATH_INFO from SCRIPT_NAME - scriptName = strings.TrimSuffix(scriptName, pathInfo) - // SCRIPT_FILENAME is the absolute path of SCRIPT_NAME scriptFilename := filepath.Join(root, scriptName)