Commit f9cba03d authored by Matthew Holt's avatar Matthew Holt

redir: Do not count multiple rules with if statements as duplicates

This allows you to have multiple redir directives conditioned solely
upon if statements, without regard to path.
parent baf6db5b
......@@ -40,6 +40,7 @@ func SetupIfMatcher(controller *caddy.Controller) (RequestMatcher, error) {
return matcher, err
}
matcher.ifs = append(matcher.ifs, ifc)
matcher.Enabled = true
case "if_op":
if !c.NextArg() {
return matcher, c.ArgErr()
......@@ -155,6 +156,7 @@ func (i ifCond) True(r *http.Request) bool {
// IfMatcher is a RequestMatcher for 'if' conditions.
type IfMatcher struct {
Enabled bool // if true, matcher has been configured; otherwise it's no-op
ifs []ifCond // list of If
isOr bool // if true, conditions are 'or' instead of 'and'
}
......
......@@ -101,11 +101,14 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
return c.Err("'from' and 'to' values of redirect rule cannot be the same")
}
// prevent obvious duplicates (rules with if statements exempt)
if ifm, ok := rule.RequestMatcher.(httpserver.IfMatcher); !ok || !ifm.Enabled {
for _, otherRule := range redirects {
if otherRule.FromPath == rule.FromPath {
return c.Errf("rule with duplicate 'from' value: %s -> %s", otherRule.FromPath, otherRule.To)
}
}
}
redirects = append(redirects, rule)
return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment