MCPcopy
hub / github.com/caddyserver/caddy / MatchWithError

Method MatchWithError

modules/caddyhttp/routes.go:371–396  ·  modules/caddyhttp/routes.go::MatcherSet.MatchWithError

MatchWithError returns true if r matches m.

(r *http.Request)

Source from the content-addressed store, hash-verified

369
370// MatchWithError returns true if r matches m.
371func (mset MatcherSet) MatchWithError(r *http.Request) (bool, error) {
372 for _, m := range mset {
373 if me, ok := m.(RequestMatcherWithError); ok {
374 match, err := me.MatchWithError(r)
375 if err != nil || !match {
376 return match, err
377 }
378 continue
379 }
380 if me, ok := m.(RequestMatcher); ok {
381 if !me.Match(r) {
382 // for backwards compatibility
383 err, ok := GetVar(r.Context(), MatcherErrorVarKey).(error)
384 if ok {
385 // clear out the error from context since we've consumed it
386 SetVar(r.Context(), MatcherErrorVarKey, nil)
387 return false, err
388 }
389 return false, nil
390 }
391 continue
392 }
393 return false, fmt.Errorf("matcher is not a RequestMatcher or RequestMatcherWithError: %#v", m)
394 }
395 return true, nil
396}
397
398// RawMatcherSets is a group of matcher sets
399// in their raw, JSON form.

Callers

nothing calls this directly

Calls 4

GetVarFunction · 0.85
SetVarFunction · 0.85
MatchWithErrorMethod · 0.65
MatchMethod · 0.65

Tested by

no test coverage detected