summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-05-11 16:38:33 -0400
committerGitHub <noreply@github.com>2020-05-11 14:38:33 -0600
commit4c55d26f11329243591d04ca5a52298b38bca9a8 (patch)
tree27557f2dd51e711d455434b9d760a55651406388 /modules/caddyhttp
parentd5341625561bf67c40241a4fb649b0a4991e71b2 (diff)
caddyhttp: Fix merging of Caddyfile matchers in not blocks (#3379)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/matchers.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 95100d5..0860780 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -592,8 +592,17 @@ func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
var mp matcherPair
matcherMap := make(map[string]RequestMatcher)
- for d.NextArg() || d.NextBlock(0) {
+
+ // in case there are multiple instances of the same matcher, concatenate
+ // their tokens (we expect that UnmarshalCaddyfile should be able to
+ // handle more than one segment); otherwise, we'd overwrite other
+ // instances of the matcher in this set
+ tokensByMatcherName := make(map[string][]caddyfile.Token)
+ for nesting := d.Nesting(); d.NextArg() || d.NextBlock(nesting); {
matcherName := d.Val()
+ tokensByMatcherName[matcherName] = append(tokensByMatcherName[matcherName], d.NextSegment()...)
+ }
+ for matcherName, tokens := range tokensByMatcherName {
mod, err := caddy.GetModule("http.matchers." + matcherName)
if err != nil {
return d.Errf("getting matcher module '%s': %v", matcherName, err)
@@ -602,11 +611,14 @@ func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
if !ok {
return d.Errf("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
}
- err = unm.UnmarshalCaddyfile(d.NewFromNextSegment())
+ err = unm.UnmarshalCaddyfile(caddyfile.NewDispenser(tokens))
if err != nil {
return err
}
- rm := unm.(RequestMatcher)
+ rm, ok := unm.(RequestMatcher)
+ if !ok {
+ return fmt.Errorf("matcher module '%s' is not a request matcher", matcherName)
+ }
matcherMap[matcherName] = rm
mp.decoded = append(mp.decoded, rm)
}