mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	Merge pull request #2158 from caldwell/script_filename-fix
fastcgi: strip PATH_INFO from SCRIPT_FILENAME (mirroring SCRIPT_NAME)
This commit is contained in:
		
						commit
						4829cc6aaf
					
				| @ -242,9 +242,6 @@ func (h Handler) exists(path string) bool { | |||||||
| func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string]string, error) { | func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string]string, error) { | ||||||
| 	var env map[string]string | 	var env map[string]string | ||||||
| 
 | 
 | ||||||
| 	// Get absolute path of requested resource |  | ||||||
| 	absPath := filepath.Join(rule.Root, fpath) |  | ||||||
| 
 |  | ||||||
| 	// Separate remote IP and port; more lenient than net.SplitHostPort | 	// Separate remote IP and port; more lenient than net.SplitHostPort | ||||||
| 	var ip, port string | 	var ip, port string | ||||||
| 	if idx := strings.LastIndex(r.RemoteAddr, ":"); idx > -1 { | 	if idx := strings.LastIndex(r.RemoteAddr, ":"); idx > -1 { | ||||||
| @ -266,11 +263,13 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] | |||||||
| 	docURI := fpath[:splitPos+len(rule.SplitPath)] | 	docURI := fpath[:splitPos+len(rule.SplitPath)] | ||||||
| 	pathInfo := fpath[splitPos+len(rule.SplitPath):] | 	pathInfo := fpath[splitPos+len(rule.SplitPath):] | ||||||
| 	scriptName := fpath | 	scriptName := fpath | ||||||
| 	scriptFilename := absPath |  | ||||||
| 
 | 
 | ||||||
| 	// Strip PATH_INFO from SCRIPT_NAME | 	// Strip PATH_INFO from SCRIPT_NAME | ||||||
| 	scriptName = strings.TrimSuffix(scriptName, pathInfo) | 	scriptName = strings.TrimSuffix(scriptName, pathInfo) | ||||||
| 
 | 
 | ||||||
|  | 	// SCRIPT_FILENAME is the absolute path of SCRIPT_NAME | ||||||
|  | 	scriptFilename := filepath.Join(rule.Root, scriptName) | ||||||
|  | 
 | ||||||
| 	// Add vhost path prefix to scriptName. Otherwise, some PHP software will | 	// Add vhost path prefix to scriptName. Otherwise, some PHP software will | ||||||
| 	// have difficulty discovering its URL. | 	// have difficulty discovering its URL. | ||||||
| 	pathPrefix, _ := r.Context().Value(caddy.CtxKey("path_prefix")).(string) | 	pathPrefix, _ := r.Context().Value(caddy.CtxKey("path_prefix")).(string) | ||||||
|  | |||||||
| @ -21,6 +21,7 @@ import ( | |||||||
| 	"net/http/fcgi" | 	"net/http/fcgi" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | 	"path/filepath" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"testing" | 	"testing" | ||||||
| @ -238,6 +239,15 @@ func TestBuildEnv(t *testing.T) { | |||||||
| 	envExpected = newEnv() | 	envExpected = newEnv() | ||||||
| 	envExpected["SCRIPT_NAME"] = "/test/fgci_test.php" | 	envExpected["SCRIPT_NAME"] = "/test/fgci_test.php" | ||||||
| 	testBuildEnv(r, rule, fpath, envExpected) | 	testBuildEnv(r, rule, fpath, envExpected) | ||||||
|  | 
 | ||||||
|  | 	// 7. Test SCRIPT_NAME,SCRIPT_FILENAME do not include PATH_INFO | ||||||
|  | 	fpath = "/fgci_test.php/extra/paths" | ||||||
|  | 	r = newReq() | ||||||
|  | 	envExpected = newEnv() | ||||||
|  | 	envExpected["PATH_INFO"] = "/extra/paths" | ||||||
|  | 	envExpected["SCRIPT_NAME"] = "/fgci_test.php" | ||||||
|  | 	envExpected["SCRIPT_FILENAME"] = filepath.FromSlash("/fgci_test.php") | ||||||
|  | 	testBuildEnv(r, rule, fpath, envExpected) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestReadTimeout(t *testing.T) { | func TestReadTimeout(t *testing.T) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user