matchers: fix a regression in #6480 (#6510)

The context may have no replacer
This commit is contained in:
vnxme 2024-08-12 10:01:09 +03:00 committed by GitHub
parent 21af88fefc
commit 7cf8376e63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,12 +50,13 @@ func (MatchServerName) CaddyModule() caddy.ModuleInfo {
// Match matches hello based on SNI.
func (m MatchServerName) Match(hello *tls.ClientHelloInfo) bool {
repl := caddy.NewReplacer()
// caddytls.TestServerNameMatcher calls this function without any context
var repl *caddy.Replacer
if ctx := hello.Context(); ctx != nil {
repl = ctx.Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
} else {
repl = caddy.NewReplacer()
// In some situations the existing context may have no replacer
if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil {
repl = replAny.(*caddy.Replacer)
}
}
for _, name := range m {