diff options
author | Francis Lavoie <lavofr@gmail.com> | 2020-11-02 18:05:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-02 16:05:01 -0700 |
commit | b4f49e2962201a87037f451a0b68323524828a58 (patch) | |
tree | ec68757df5504790ac2ef2d811861351624c4471 /modules/caddyhttp | |
parent | dd26875ffcbec8b74234bdda64e019a8a20c37e2 (diff) |
caddyhttp: Merge query matchers in Caddyfile (#3839)
Also, turns out that `Add` on headers will work even if there's nothing there yet, so we can remove the condition I introduced in #3832
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/matchers.go | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index cbb6253..b7a304f 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -353,18 +353,16 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { *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()) + for _, query := range d.RemainingArgs() { + 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()) + } + url.Values(*m).Add(parts[0], parts[1]) } - url.Values(*m).Set(parts[0], parts[1]) if d.NextBlock(0) { return d.Err("malformed query matcher: blocks are not supported") } @@ -411,12 +409,7 @@ func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { // If multiple header matchers with the same header field are defined, // we want to add the existing to the list of headers (will be OR'ed) - existing := http.Header(*m).Values(field) - if len(existing) > 0 { - http.Header(*m).Add(field, val) - } else { - http.Header(*m).Set(field, val) - } + http.Header(*m).Add(field, val) if d.NextBlock(0) { return d.Err("malformed header matcher: blocks are not supported") |