UnmarshalCaddyfile implements caddyfile.Unmarshaler.
(d *caddyfile.Dispenser)
| 230 | |
| 231 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 232 | func (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. |
| 268 | type MatchServerNameRE struct{ MatchRegexp } |
nothing calls this directly
no test coverage detected