mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
caddyfile: Populate regexp matcher names by default (#6145)
* caddyfile: Populate regexp matcher names by default * Some lint cleanup that my VSCode complained about * Pass down matcher name through expression matcher * Compat with #6113: fix adapt test, set both styles in replacer
This commit is contained in:
parent
e0daa39cd3
commit
9cd472c031
14 changed files with 183 additions and 27 deletions
|
@ -1397,6 +1397,14 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
|
|||
// given a matcher name and the tokens following it, parse
|
||||
// the tokens as a matcher module and record it
|
||||
makeMatcher := func(matcherName string, tokens []caddyfile.Token) error {
|
||||
// create a new dispenser from the tokens
|
||||
dispenser := caddyfile.NewDispenser(tokens)
|
||||
|
||||
// set the matcher name (without @) in the dispenser context so
|
||||
// that matcher modules can access it to use it as their name
|
||||
// (e.g. regexp matchers which use the name for capture groups)
|
||||
dispenser.SetContext(caddyfile.MatcherNameCtxKey, definitionName[1:])
|
||||
|
||||
mod, err := caddy.GetModule("http.matchers." + matcherName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting matcher module '%s': %v", matcherName, err)
|
||||
|
@ -1405,7 +1413,7 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M
|
|||
if !ok {
|
||||
return fmt.Errorf("matcher module '%s' is not a Caddyfile unmarshaler", matcherName)
|
||||
}
|
||||
err = unm.UnmarshalCaddyfile(caddyfile.NewDispenser(tokens))
|
||||
err = unm.UnmarshalCaddyfile(dispenser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue