caddyhttp: Support placeholders in query matcher (#3521)

This commit is contained in:
James Birtles
2020-06-26 22:14:47 +01:00
committed by GitHub
parent 6004d3f779
commit ddd690de4c
2 changed files with 20 additions and 0 deletions

View File

@ -374,10 +374,13 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Match returns true if r matches m. An empty m matches an empty query string.
func (m MatchQuery) Match(r *http.Request) bool {
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
for param, vals := range m {
param = repl.ReplaceAll(param, "")
paramVal, found := r.URL.Query()[param]
if found {
for _, v := range vals {
v = repl.ReplaceAll(v, "")
if paramVal[0] == v || v == "*" {
return true
}