aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/matchers.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2024-03-03 05:14:38 -0500
committerFrancis Lavoie <[email protected]>2024-04-17 11:57:30 -0400
commit9b757ce862fcaf5535c07ef67c233dfc358316ef (patch)
tree438d1313ea339d19e554b64b34052ea8361f0b12 /modules/caddyhttp/matchers.go
parent244ef288a9fb81366c65976a14d2d5642e9ed24e (diff)
downloadcaddy-9b757ce862fcaf5535c07ef67c233dfc358316ef.tar.gz
caddy-9b757ce862fcaf5535c07ef67c233dfc358316ef.zip
Pass down matcher name through expression matcher
Diffstat (limited to 'modules/caddyhttp/matchers.go')
-rw-r--r--modules/caddyhttp/matchers.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 8aca605ec..23dc6e8a8 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -675,7 +675,10 @@ func (MatchPathRE) CELLibrary(ctx caddy.Context) (cel.Library, error) {
[]*cel.Type{cel.StringType},
func(data ref.Val) (RequestMatcher, error) {
pattern := data.(types.String)
- matcher := MatchPathRE{MatchRegexp{Pattern: string(pattern)}}
+ matcher := MatchPathRE{MatchRegexp{
+ Name: ctx.Value(MatcherNameCtxKey).(string),
+ Pattern: string(pattern),
+ }}
err := matcher.Provision(ctx)
return matcher, err
},
@@ -694,7 +697,14 @@ func (MatchPathRE) CELLibrary(ctx caddy.Context) (cel.Library, error) {
return nil, err
}
strParams := params.([]string)
- matcher := MatchPathRE{MatchRegexp{Name: strParams[0], Pattern: strParams[1]}}
+ name := strParams[0]
+ if name == "" {
+ name = ctx.Value(MatcherNameCtxKey).(string)
+ }
+ matcher := MatchPathRE{MatchRegexp{
+ Name: name,
+ Pattern: strParams[1],
+ }}
err = matcher.Provision(ctx)
return matcher, err
},
@@ -1104,7 +1114,10 @@ func (MatchHeaderRE) CELLibrary(ctx caddy.Context) (cel.Library, error) {
}
strParams := params.([]string)
matcher := MatchHeaderRE{}
- matcher[strParams[0]] = &MatchRegexp{Pattern: strParams[1], Name: ""}
+ matcher[strParams[0]] = &MatchRegexp{
+ Pattern: strParams[1],
+ Name: ctx.Value(MatcherNameCtxKey).(string),
+ }
err = matcher.Provision(ctx)
return matcher, err
},
@@ -1123,8 +1136,15 @@ func (MatchHeaderRE) CELLibrary(ctx caddy.Context) (cel.Library, error) {
return nil, err
}
strParams := params.([]string)
+ name := strParams[0]
+ if name == "" {
+ name = ctx.Value(MatcherNameCtxKey).(string)
+ }
matcher := MatchHeaderRE{}
- matcher[strParams[1]] = &MatchRegexp{Pattern: strParams[2], Name: strParams[0]}
+ matcher[strParams[1]] = &MatchRegexp{
+ Pattern: strParams[2],
+ Name: name,
+ }
err = matcher.Provision(ctx)
return matcher, err
},