Keep AnyMatch signature the same for now

This commit is contained in:
Francis Lavoie 2024-10-13 17:56:22 -04:00
parent 5c5f7c2877
commit c8e38e4a33
2 changed files with 26 additions and 7 deletions

View File

@ -1124,7 +1124,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int
return false
}
match, err := lb.RetryMatch.AnyMatch(req)
match, err := lb.RetryMatch.AnyMatchWithError(req)
if err != nil {
logger.Error("error matching request for retry", zap.Error(err))
return false

View File

@ -254,7 +254,7 @@ func wrapRoute(route Route) Middleware {
nextCopy := next
// route must match at least one of the matcher sets
matches, err := route.MatcherSets.AnyMatch(req)
matches, err := route.MatcherSets.AnyMatchWithError(req)
if err != nil {
// allow matchers the opportunity to short circuit
// the request and trigger the error handling chain
@ -397,11 +397,30 @@ type RawMatcherSets []caddy.ModuleMap
// the sets.
type MatcherSets []MatcherSet
// AnyMatch returns true if req matches any of the matcher sets
// in ms or if there are no matchers, in which case the request
// always matches. If any matcher returns an error, we cut short
// and return the error.
func (ms MatcherSets) AnyMatch(req *http.Request) (bool, error) {
// AnyMatch returns true if req matches any of the
// matcher sets in ms or if there are no matchers,
// in which case the request always matches.
//
// Deprecated: Use AnyMatchWithError instead.
func (ms MatcherSets) AnyMatch(req *http.Request) bool {
for _, m := range ms {
match, err := m.MatchWithError(req)
if err != nil {
SetVar(req.Context(), MatcherErrorVarKey, err)
return false
}
if match {
return match
}
}
return len(ms) == 0
}
// AnyMatchWithError returns true if req matches any of the
// matcher sets in ms or if there are no matchers, in which
// case the request always matches. If any matcher returns
// an error, we cut short and return the error.
func (ms MatcherSets) AnyMatchWithError(req *http.Request) (bool, error) {
for _, m := range ms {
match, err := m.MatchWithError(req)
if err != nil || match {