Skip to content

Commit

Permalink
Fix a regression in caddyserver#6480: the context may have no replace…
Browse files Browse the repository at this point in the history
…r (e.g. in TestDefaultSNI)
  • Loading branch information
vnxme committed Aug 11, 2024
1 parent 21af88f commit 30d0ddb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/caddytls/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 30d0ddb

Please sign in to comment.