mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	Add REQUEST_SCHEME to fastcgi envs
Fixes https://github.com/mholt/caddy/issues/2152
This commit is contained in:
		
							parent
							
								
									4829cc6aaf
								
							
						
					
					
						commit
						2aaaa368bb
					
				| @ -285,6 +285,11 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] | |||||||
| 	// Retrieve name of remote user that was set by some downstream middleware such as basicauth. | 	// Retrieve name of remote user that was set by some downstream middleware such as basicauth. | ||||||
| 	remoteUser, _ := r.Context().Value(httpserver.RemoteUserCtxKey).(string) | 	remoteUser, _ := r.Context().Value(httpserver.RemoteUserCtxKey).(string) | ||||||
| 
 | 
 | ||||||
|  | 	requestScheme := "http" | ||||||
|  | 	if r.TLS != nil { | ||||||
|  | 		requestScheme = "https" | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// Some variables are unused but cleared explicitly to prevent | 	// Some variables are unused but cleared explicitly to prevent | ||||||
| 	// the parent environment from interfering. | 	// the parent environment from interfering. | ||||||
| 	env = map[string]string{ | 	env = map[string]string{ | ||||||
| @ -301,6 +306,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string] | |||||||
| 		"REMOTE_IDENT":      "", // Not used | 		"REMOTE_IDENT":      "", // Not used | ||||||
| 		"REMOTE_USER":       remoteUser, | 		"REMOTE_USER":       remoteUser, | ||||||
| 		"REQUEST_METHOD":    r.Method, | 		"REQUEST_METHOD":    r.Method, | ||||||
|  | 		"REQUEST_SCHEME":    requestScheme, | ||||||
| 		"SERVER_NAME":       h.ServerName, | 		"SERVER_NAME":       h.ServerName, | ||||||
| 		"SERVER_PORT":       h.ServerPort, | 		"SERVER_PORT":       h.ServerPort, | ||||||
| 		"SERVER_PROTOCOL":   r.Proto, | 		"SERVER_PROTOCOL":   r.Proto, | ||||||
|  | |||||||
| @ -248,6 +248,12 @@ func TestBuildEnv(t *testing.T) { | |||||||
| 	envExpected["SCRIPT_NAME"] = "/fgci_test.php" | 	envExpected["SCRIPT_NAME"] = "/fgci_test.php" | ||||||
| 	envExpected["SCRIPT_FILENAME"] = filepath.FromSlash("/fgci_test.php") | 	envExpected["SCRIPT_FILENAME"] = filepath.FromSlash("/fgci_test.php") | ||||||
| 	testBuildEnv(r, rule, fpath, envExpected) | 	testBuildEnv(r, rule, fpath, envExpected) | ||||||
|  | 
 | ||||||
|  | 	// 8. Test REQUEST_SCHEME in env | ||||||
|  | 	r = newReq() | ||||||
|  | 	envExpected = newEnv() | ||||||
|  | 	envExpected["REQUEST_SCHEME"] = "http" | ||||||
|  | 	testBuildEnv(r, rule, fpath, envExpected) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestReadTimeout(t *testing.T) { | func TestReadTimeout(t *testing.T) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user