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

Method UnmarshalCaddyfile

modules/caddyhttp/celmatcher.go:227–255  ·  view source on GitHub ↗

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

225
226// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
227func (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.

Callers

nothing calls this directly

Calls 7

CountRemainingArgsMethod · 0.80
RemainingArgsRawMethod · 0.80
NextArgMethod · 0.80
ArgErrMethod · 0.80
ValMethod · 0.80
GetContextStringMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected