diff --git a/modules/l4tls/alpn_matcher.go b/modules/l4tls/alpn_matcher.go index e5ea95f..71f1ef0 100644 --- a/modules/l4tls/alpn_matcher.go +++ b/modules/l4tls/alpn_matcher.go @@ -37,7 +37,14 @@ func (*MatchALPN) CaddyModule() caddy.ModuleInfo { } func (m *MatchALPN) Match(hello *tls.ClientHelloInfo) bool { - repl := hello.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) + repl := caddy.NewReplacer() + if ctx := hello.Context(); ctx != nil { + // In some situations the existing context may have no replacer + if replAny := ctx.Value(caddy.ReplacerCtxKey); replAny != nil { + repl = replAny.(*caddy.Replacer) + } + } + clientProtocols := hello.SupportedProtos for _, alpn := range *m { alpn = repl.ReplaceAll(alpn, "")