diff options
author | Francis Lavoie <[email protected]> | 2024-11-27 22:32:26 -0500 |
---|---|---|
committer | Francis Lavoie <[email protected]> | 2024-12-01 17:21:44 -0500 |
commit | 2e6f62606764adfafdbef5daff3562bd53a4bc82 (patch) | |
tree | 1b9400fc190dda766feefa93dbbece8d416cb161 | |
parent | 16d5b22349e7fe6aac876c2581df954578f595fd (diff) | |
download | caddy-2e6f62606764adfafdbef5daff3562bd53a4bc82.tar.gz caddy-2e6f62606764adfafdbef5daff3562bd53a4bc82.zip |
caddyhttp: Add `{prefixed_query}` placeholder
-rw-r--r-- | caddyconfig/httpcaddyfile/shorthands.go | 1 | ||||
-rw-r--r-- | modules/caddyhttp/replacer.go | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/shorthands.go b/caddyconfig/httpcaddyfile/shorthands.go index 5d9ef31eb..8ebaed878 100644 --- a/caddyconfig/httpcaddyfile/shorthands.go +++ b/caddyconfig/httpcaddyfile/shorthands.go @@ -60,6 +60,7 @@ func placeholderShorthands() []string { "{method}", "{http.request.method}", "{path}", "{http.request.uri.path}", "{query}", "{http.request.uri.query}", + "{prefixed_query}", "{http.request.uri.prefixed_query}", "{remote}", "{http.request.remote}", "{remote_host}", "{http.request.remote.host}", "{remote_port}", "{http.request.remote.port}", diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go index 2c0f32357..bb2623771 100644 --- a/modules/caddyhttp/replacer.go +++ b/modules/caddyhttp/replacer.go @@ -186,6 +186,11 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo return path.Ext(req.URL.Path), true case "http.request.uri.query": return req.URL.RawQuery, true + case "http.request.uri.prefixed_query": + if req.URL.RawQuery == "" { + return "", true + } + return "?" + req.URL.RawQuery, true case "http.request.duration": start := GetVar(req.Context(), "start_time").(time.Time) return time.Since(start), true |