summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-06-16 10:41:37 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-06-16 10:41:37 -0600
commit6db3615547b8911ac81dc2b23c1ed8bedbef0fdb (patch)
treef361571f3699ac59b882f30a08756fe9ba828364 /modules/caddyhttp/matchers.go
parent32cafbb6309c8d78cc7e2f2a75def9c633944ef8 (diff)
caddyhttp: Enable matching empty query string
Caddyfile syntax: query "" Or a nil matcher in the JSON should also match an empty query string. See https://caddy.community/t/v2-match-empty-query/8708?u=matt
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 5dddb71..6662dac 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -349,19 +349,21 @@ func (MatchQuery) CaddyModule() caddy.ModuleInfo {
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
- if *m == nil {
- *m = make(map[string][]string)
- }
-
for d.Next() {
var query string
if !d.Args(&query) {
return d.ArgErr()
}
+ if query == "" {
+ continue
+ }
parts := strings.SplitN(query, "=", 2)
if len(parts) != 2 {
return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val())
}
+ if *m == nil {
+ *m = make(map[string][]string)
+ }
url.Values(*m).Set(parts[0], parts[1])
if d.NextBlock(0) {
return d.Err("malformed query matcher: blocks are not supported")
@@ -372,6 +374,9 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// Match returns true if r matches m.
func (m MatchQuery) Match(r *http.Request) bool {
+ if m == nil {
+ return len(r.URL.Query()) == 0
+ }
for param, vals := range m {
paramVal, found := r.URL.Query()[param]
if found {