mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
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.
This commit is contained in:
parent
baf6db5b57
commit
f9cba03d25
|
@ -40,6 +40,7 @@ func SetupIfMatcher(controller *caddy.Controller) (RequestMatcher, error) {
|
||||||
return matcher, err
|
return matcher, err
|
||||||
}
|
}
|
||||||
matcher.ifs = append(matcher.ifs, ifc)
|
matcher.ifs = append(matcher.ifs, ifc)
|
||||||
|
matcher.Enabled = true
|
||||||
case "if_op":
|
case "if_op":
|
||||||
if !c.NextArg() {
|
if !c.NextArg() {
|
||||||
return matcher, c.ArgErr()
|
return matcher, c.ArgErr()
|
||||||
|
@ -155,8 +156,9 @@ func (i ifCond) True(r *http.Request) bool {
|
||||||
|
|
||||||
// IfMatcher is a RequestMatcher for 'if' conditions.
|
// IfMatcher is a RequestMatcher for 'if' conditions.
|
||||||
type IfMatcher struct {
|
type IfMatcher struct {
|
||||||
ifs []ifCond // list of If
|
Enabled bool // if true, matcher has been configured; otherwise it's no-op
|
||||||
isOr bool // if true, conditions are 'or' instead of 'and'
|
ifs []ifCond // list of If
|
||||||
|
isOr bool // if true, conditions are 'or' instead of 'and'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match satisfies RequestMatcher interface.
|
// Match satisfies RequestMatcher interface.
|
||||||
|
|
|
@ -101,9 +101,12 @@ func redirParse(c *caddy.Controller) ([]Rule, error) {
|
||||||
return c.Err("'from' and 'to' values of redirect rule cannot be the same")
|
return c.Err("'from' and 'to' values of redirect rule cannot be the same")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, otherRule := range redirects {
|
// prevent obvious duplicates (rules with if statements exempt)
|
||||||
if otherRule.FromPath == rule.FromPath {
|
if ifm, ok := rule.RequestMatcher.(httpserver.IfMatcher); !ok || !ifm.Enabled {
|
||||||
return c.Errf("rule with duplicate 'from' value: %s -> %s", otherRule.FromPath, otherRule.To)
|
for _, otherRule := range redirects {
|
||||||
|
if otherRule.FromPath == rule.FromPath {
|
||||||
|
return c.Errf("rule with duplicate 'from' value: %s -> %s", otherRule.FromPath, otherRule.To)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user