|  | @ -19,6 +19,7 @@ import ( | 
			
		
	
		
		
			
				
					|  |  | 	"net" |  |  | 	"net" | 
			
		
	
		
		
			
				
					|  |  | 	"net/http" |  |  | 	"net/http" | 
			
		
	
		
		
			
				
					|  |  | 	"net/textproto" |  |  | 	"net/textproto" | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	"net/url" | 
			
		
	
		
		
			
				
					|  |  | 	"path" |  |  | 	"path" | 
			
		
	
		
		
			
				
					|  |  | 	"strconv" |  |  | 	"strconv" | 
			
		
	
		
		
			
				
					|  |  | 	"strings" |  |  | 	"strings" | 
			
		
	
	
		
		
			
				
					|  | @ -59,6 +60,15 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon | 
			
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 			switch key { |  |  | 			switch key { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.method": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return req.Method, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.scheme": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				if req.TLS != nil { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					return "https", true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return "http", true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.proto": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return req.Proto, true | 
			
		
	
		
		
			
				
					|  |  | 			case "http.request.host": |  |  | 			case "http.request.host": | 
			
		
	
		
		
			
				
					|  |  | 				host, _, err := net.SplitHostPort(req.Host) |  |  | 				host, _, err := net.SplitHostPort(req.Host) | 
			
		
	
		
		
			
				
					|  |  | 				if err != nil { |  |  | 				if err != nil { | 
			
		
	
	
		
		
			
				
					|  | @ -81,13 +91,8 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon | 
			
		
	
		
		
			
				
					|  |  | 			case "http.request.remote.port": |  |  | 			case "http.request.remote.port": | 
			
		
	
		
		
			
				
					|  |  | 				_, port, _ := net.SplitHostPort(req.RemoteAddr) |  |  | 				_, port, _ := net.SplitHostPort(req.RemoteAddr) | 
			
		
	
		
		
			
				
					|  |  | 				return port, true |  |  | 				return port, true | 
			
		
	
		
		
			
				
					
					|  |  | 			case "http.request.method": |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 				return req.Method, true |  |  | 			// current URI, including any internal rewrites
 | 
			
				
				
			
		
	
		
		
			
				
					|  |  | 			case "http.request.scheme": |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				if req.TLS != nil { |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 					return "https", true |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				} |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 				return "http", true |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 			case "http.request.uri": |  |  | 			case "http.request.uri": | 
			
		
	
		
		
			
				
					|  |  | 				return req.URL.RequestURI(), true |  |  | 				return req.URL.RequestURI(), true | 
			
		
	
		
		
			
				
					|  |  | 			case "http.request.uri.path": |  |  | 			case "http.request.uri.path": | 
			
		
	
	
		
		
			
				
					|  | @ -106,6 +111,32 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon | 
			
		
	
		
		
			
				
					|  |  | 					qs = "?" + qs |  |  | 					qs = "?" + qs | 
			
		
	
		
		
			
				
					|  |  | 				} |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  | 				return qs, true |  |  | 				return qs, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			// original URI, before any internal changes
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return u.RequestURI(), true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri.path": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return u.Path, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri.path.file": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				_, file := path.Split(u.Path) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return file, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri.path.dir": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				dir, _ := path.Split(u.Path) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return dir, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri.query": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return u.RawQuery, true | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			case "http.request.orig_uri.query_string": | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				u, _ := req.Context().Value(OriginalURLCtxKey).(url.URL) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				qs := u.Query().Encode() | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				if qs != "" { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					qs = "?" + qs | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				return qs, true | 
			
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 			// hostname labels
 |  |  | 			// hostname labels
 | 
			
		
	
	
		
		
			
				
					|  | 
 |