File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 15
15
package caddytls
16
16
17
17
import (
18
+ "context"
18
19
"crypto/tls"
19
20
"fmt"
20
21
"net"
@@ -224,15 +225,28 @@ func (MatchServerNameRE) CaddyModule() caddy.ModuleInfo {
224
225
225
226
// Match matches hello based on SNI using a regular expression.
226
227
func (m MatchServerNameRE ) Match (hello * tls.ClientHelloInfo ) bool {
227
- repl := caddy .NewReplacer ()
228
- // caddytls.TestServerNameMatcher calls this function without any context
229
- if ctx := hello .Context (); ctx != nil {
228
+ // Note: caddytls.TestServerNameMatcher calls this function without any context
229
+ ctx := hello .Context ()
230
+ if ctx == nil {
231
+ // layer4.Connection implements GetContext() to pass its context here,
232
+ // since hello.Context() returns nil
233
+ if mayHaveContext , ok := hello .Conn .(interface { GetContext () context.Context }); ok {
234
+ ctx = mayHaveContext .GetContext ()
235
+ }
236
+ }
237
+
238
+ var repl * caddy.Replacer
239
+ if ctx != nil {
230
240
// In some situations the existing context may have no replacer
231
241
if replAny := ctx .Value (caddy .ReplacerCtxKey ); replAny != nil {
232
242
repl = replAny .(* caddy.Replacer )
233
243
}
234
244
}
235
245
246
+ if repl == nil {
247
+ repl = caddy .NewReplacer ()
248
+ }
249
+
236
250
return m .MatchRegexp .Match (hello .ServerName , repl )
237
251
}
238
252
You can’t perform that action at this time.
0 commit comments