mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05:00 
			
		
		
		
	Add query_string to HTTP replacer and use it for try_files
This commit is contained in:
		
							parent
							
								
									2dc4fcc62b
								
							
						
					
					
						commit
						d242f10eda
					
				@ -17,9 +17,9 @@ package fileserver
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
 | 
					 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
 | 
						"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
 | 
				
			||||||
	"github.com/caddyserver/caddy/v2/modules/caddyhttp"
 | 
						"github.com/caddyserver/caddy/v2/modules/caddyhttp"
 | 
				
			||||||
 | 
						"github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
@ -99,7 +99,7 @@ func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	handler := rewrite.Rewrite{
 | 
						handler := rewrite.Rewrite{
 | 
				
			||||||
		URI: "{http.matchers.file.relative}{http.request.uri.query}",
 | 
							URI: "{http.matchers.file.relative}{http.request.uri.query_string}",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	matcherSet := map[string]json.RawMessage{
 | 
						matcherSet := map[string]json.RawMessage{
 | 
				
			||||||
 | 
				
			|||||||
@ -89,6 +89,12 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
 | 
				
			|||||||
				return dir, true
 | 
									return dir, true
 | 
				
			||||||
			case "http.request.uri.query":
 | 
								case "http.request.uri.query":
 | 
				
			||||||
				return req.URL.RawQuery, true
 | 
									return req.URL.RawQuery, true
 | 
				
			||||||
 | 
								case "http.request.uri.query_string":
 | 
				
			||||||
 | 
									qs := req.URL.Query().Encode()
 | 
				
			||||||
 | 
									if qs != "" {
 | 
				
			||||||
 | 
										qs = "?" + qs
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return qs, true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// hostname labels
 | 
								// hostname labels
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user