UnmarshalCaddyfile implements caddyfile.Unmarshaler.
(d *caddyfile.Dispenser)
| 225 | |
| 226 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 227 | func (m *MatchExpression) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
| 228 | d.Next() // consume matcher name |
| 229 | |
| 230 | // if there's multiple args, then we need to keep the raw |
| 231 | // tokens because the user may have used quotes within their |
| 232 | // CEL expression (e.g. strings) and we should retain that |
| 233 | if d.CountRemainingArgs() > 1 { |
| 234 | m.Expr = strings.Join(d.RemainingArgsRaw(), " ") |
| 235 | return nil |
| 236 | } |
| 237 | |
| 238 | // there should at least be one arg |
| 239 | if !d.NextArg() { |
| 240 | return d.ArgErr() |
| 241 | } |
| 242 | |
| 243 | // if there's only one token, then we can safely grab the |
| 244 | // cleaned token (no quotes) and use that as the expression |
| 245 | // because there's no valid CEL expression that is only a |
| 246 | // quoted string; commonly quotes are used in Caddyfile to |
| 247 | // define the expression |
| 248 | m.Expr = d.Val() |
| 249 | |
| 250 | // use the named matcher's name, to fill regexp |
| 251 | // matchers names by default |
| 252 | m.Name = d.GetContextString(caddyfile.MatcherNameCtxKey) |
| 253 | |
| 254 | return nil |
| 255 | } |
| 256 | |
| 257 | // caddyPlaceholderFunc implements the custom CEL function that accesses the |
| 258 | // Replacer on a request and gets values from it. |
nothing calls this directly
no test coverage detected