caddyhttp: Add {prefixed_query} placeholder

This commit is contained in:
Francis Lavoie 2024-11-27 22:32:26 -05:00
parent 22b9d51268
commit 533a77c3fd
No known key found for this signature in database
GPG Key ID: 52BC55A211F19186
2 changed files with 6 additions and 0 deletions

View File

@ -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}",

View File

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