summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-08-27 14:38:24 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-08-27 14:38:24 -0600
commitd242f10eda8fdd52f86701cf3685090e9761489f (patch)
tree1b13f2f3e8dbc09f2a697a40b5e99f481039a13d /modules/caddyhttp
parent2dc4fcc62bfab639b60758f26659c03e58af9960 (diff)
Add query_string to HTTP replacer and use it for try_files
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/fileserver/caddyfile.go4
-rw-r--r--modules/caddyhttp/replacer.go6
2 files changed, 8 insertions, 2 deletions
diff --git a/modules/caddyhttp/fileserver/caddyfile.go b/modules/caddyhttp/fileserver/caddyfile.go
index 7afcc9e..6480598 100644
--- a/modules/caddyhttp/fileserver/caddyfile.go
+++ b/modules/caddyhttp/fileserver/caddyfile.go
@@ -17,9 +17,9 @@ package fileserver
import (
"encoding/json"
- "github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
)
func init() {
@@ -99,7 +99,7 @@ func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
}
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{
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index cc29789..9a8a875 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -89,6 +89,12 @@ func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.Respon
return dir, true
case "http.request.uri.query":
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