summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-06-16 12:02:23 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-06-16 12:02:23 -0600
commit3af15c0725605162dc8dad0c6ab241e2dc4553c6 (patch)
tree912ea657a25561cbffbf4f40a4d5efa87dbda4e5 /modules/caddyhttp/matchers.go
parent6db3615547b8911ac81dc2b23c1ed8bedbef0fdb (diff)
caddyhttp: Empty, not nil, query matcher matches empty query string
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 6662dac..a291242 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -349,6 +349,9 @@ 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) {
@@ -361,9 +364,6 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
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,11 +372,8 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return nil
}
-// Match returns true if r matches m.
+// Match returns true if r matches m. An empty m matches an empty query string.
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 {
@@ -387,7 +384,7 @@ func (m MatchQuery) Match(r *http.Request) bool {
}
}
}
- return false
+ return len(m) == 0 && len(r.URL.Query()) == 0
}
// CaddyModule returns the Caddy module information.