Add query_string to HTTP replacer and use it for try_files

This commit is contained in:
Matthew Holt 2019-08-27 14:38:24 -06:00
parent 2dc4fcc62b
commit d242f10eda
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
2 changed files with 8 additions and 2 deletions

View file

@ -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{

View file

@ -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