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

Method Match

modules/caddytls/matchers.go:279–303  ·  view source on GitHub ↗

Match matches hello based on SNI using a regular expression.

(hello *tls.ClientHelloInfo)

Source from the content-addressed store, hash-verified

277
278// Match matches hello based on SNI using a regular expression.
279func (m MatchServerNameRE) Match(hello *tls.ClientHelloInfo) bool {
280 // Note: caddytls.TestServerNameMatcher calls this function without any context
281 ctx := hello.Context()
282 if ctx == nil {
283 // layer4.Connection implements GetContext() to pass its context here,
284 // since hello.Context() returns nil
285 if mayHaveContext, ok := hello.Conn.(interface{ GetContext() context.Context }); ok {
286 ctx = mayHaveContext.GetContext()
287 }
288 }
289
290 var repl *caddy.Replacer
291 if ctx != nil {
292 // In some situations the existing context may have no replacer
293 if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil {
294 repl = replAny.(*caddy.Replacer)
295 }
296 }
297
298 if repl == nil {
299 repl = caddy.NewReplacer()
300 }
301
302 return m.MatchRegexp.Match(hello.ServerName, repl)
303}
304
305// MatchRemoteIP matches based on the remote IP of the
306// connection. Specific IPs or CIDR ranges can be specified.

Callers 1

TestServerNameREMatcherFunction · 0.95

Calls 3

GetContextMethod · 0.80
MatchMethod · 0.65
ValueMethod · 0.45

Tested by 1

TestServerNameREMatcherFunction · 0.76