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

Method UnmarshalCaddyfile

modules/caddytls/matchers.go:232–265  ·  view source on GitHub ↗

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

230
231// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
232func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
233 // iterate to merge multiple matchers into one
234 for d.Next() {
235 // If this is the second iteration of the loop
236 // then there's more than one *_regexp matcher,
237 // and we would end up overwriting the old one
238 if mre.Pattern != "" {
239 return d.Err("regular expression can only be used once per named matcher")
240 }
241
242 args := d.RemainingArgs()
243 switch len(args) {
244 case 1:
245 mre.Pattern = args[0]
246 case 2:
247 mre.Name = args[0]
248 mre.Pattern = args[1]
249 default:
250 return d.ArgErr()
251 }
252
253 // Default to the named matcher's name, if no regexp name is provided.
254 // Note: it requires d.SetContext(caddyfile.MatcherNameCtxKey, value)
255 // called before this unmarshalling, otherwise it wouldn't work.
256 if mre.Name == "" {
257 mre.Name = d.GetContextString(caddyfile.MatcherNameCtxKey)
258 }
259
260 if d.NextBlock(0) {
261 return d.Err("malformed regexp matcher: blocks are not supported")
262 }
263 }
264 return nil
265}
266
267// MatchServerNameRE matches based on SNI using a regular expression.
268type MatchServerNameRE struct{ MatchRegexp }

Callers

nothing calls this directly

Calls 6

ErrMethod · 0.80
RemainingArgsMethod · 0.80
ArgErrMethod · 0.80
GetContextStringMethod · 0.80
NextBlockMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected