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

Function CELMatcherRuntimeFunction

modules/caddyhttp/celmatcher.go:554–585  ·  view source on GitHub ↗

CELMatcherRuntimeFunction creates a function binding for when the input to the matcher is dynamically resolved rather than a set of static constant values.

(funcName string, fac any)

Source from the content-addressed store, hash-verified

552// CELMatcherRuntimeFunction creates a function binding for when the input to the matcher
553// is dynamically resolved rather than a set of static constant values.
554func CELMatcherRuntimeFunction(funcName string, fac any) functions.BinaryOp {
555 return func(celReq, matcherData ref.Val) ref.Val {
556 if factory, ok := fac.(CELMatcherWithErrorFactory); ok {
557 matcher, err := factory(matcherData)
558 if err != nil {
559 return types.WrapErr(err)
560 }
561 httpReq := celReq.Value().(celHTTPRequest)
562 match, err := matcher.MatchWithError(httpReq.Request)
563 if err != nil {
564 return types.WrapErr(err)
565 }
566 return types.Bool(match)
567 }
568 if factory, ok := fac.(CELMatcherFactory); ok {
569 matcher, err := factory(matcherData)
570 if err != nil {
571 return types.WrapErr(err)
572 }
573 httpReq := celReq.Value().(celHTTPRequest)
574 if m, ok := matcher.(RequestMatcherWithError); ok {
575 match, err := m.MatchWithError(httpReq.Request)
576 if err != nil {
577 return types.WrapErr(err)
578 }
579 return types.Bool(match)
580 }
581 return types.Bool(matcher.Match(httpReq.Request))
582 }
583 return types.NewErr("CELMatcherRuntimeFunction invalid matcher factory: %T", fac)
584 }
585}
586
587// celMatcherStringListMacroExpander validates that the macro is called
588// with a variable number of string arguments (at least one).

Callers 2

CELLibraryMethod · 0.92
CELMatcherImplFunction · 0.85

Calls 5

WrapErrMethod · 0.80
MatchWithErrorMethod · 0.65
MatchMethod · 0.65
ValueMethod · 0.45
BoolMethod · 0.45

Tested by

no test coverage detected