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

Method Match

modules/caddytls/matchers.go:59–81  ·  view source on GitHub ↗

Match matches hello based on SNI.

(hello *tls.ClientHelloInfo)

Source from the content-addressed store, hash-verified

57
58// Match matches hello based on SNI.
59func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
60 var repl *caddy.Replacer
61 // caddytls.TestServerNameMatcher calls this function without any context
62 if ctx := hello.Context(); ctx != nil {
63 // In some situations the existing context may have no replacer
64 if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil {
65 repl = replAny.(*caddy.Replacer)
66 }
67 }
68
69 if repl == nil {
70 repl = caddy.NewReplacer()
71 }
72
73 serverName := asciiServerNameForMatch(hello.ServerName)
74 for _, name := range m {
75 rs := asciiServerNameForMatch(repl.ReplaceAll(name, ""))
76 if certmagic.MatchWildcard(serverName, rs) {
77 return true
78 }
79 }
80 return false
81}
82
83func asciiServerNameForMatch(name string) string {
84 if name == "" {

Callers

nothing calls this directly

Calls 3

ReplaceAllMethod · 0.95
asciiServerNameForMatchFunction · 0.85
ValueMethod · 0.45

Tested by

no test coverage detected