Skip to content

Commit bcef843

Browse files
authored
Use context.Context in TLS handshake (gorilla#751)
Continued work on gorilla#730.
1 parent 2c89656 commit bcef843

File tree

6 files changed

+49
-51
lines changed

6 files changed

+49
-51
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ workflows:
6767
- test:
6868
matrix:
6969
parameters:
70-
version: ["latest", "1.15", "1.14", "1.13", "1.12", "1.11"]
70+
version: ["latest", "1.17", "1.16", "1.15", "1.14", "1.13", "1.12", "1.11"]

client.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,12 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
314314
tlsConn := tls.Client(netConn, cfg)
315315
netConn = tlsConn
316316

317-
var err error
318-
if trace != nil {
319-
err = doHandshakeWithTrace(trace, tlsConn, cfg)
320-
} else {
321-
err = doHandshake(tlsConn, cfg)
317+
if trace != nil && trace.TLSHandshakeStart != nil {
318+
trace.TLSHandshakeStart()
319+
}
320+
err := doHandshake(ctx, tlsConn, cfg)
321+
if trace != nil && trace.TLSHandshakeDone != nil {
322+
trace.TLSHandshakeDone(tlsConn.ConnectionState(), err)
322323
}
323324

324325
if err != nil {
@@ -383,15 +384,3 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
383384
netConn = nil // to avoid close in defer.
384385
return conn, resp, nil
385386
}
386-
387-
func doHandshake(tlsConn *tls.Conn, cfg *tls.Config) error {
388-
if err := tlsConn.Handshake(); err != nil {
389-
return err
390-
}
391-
if !cfg.InsecureSkipVerify {
392-
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
393-
return err
394-
}
395-
}
396-
return nil
397-
}

tls_handshake.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build go1.17
2+
// +build go1.17
3+
4+
package websocket
5+
6+
import (
7+
"context"
8+
"crypto/tls"
9+
)
10+
11+
func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
12+
if err := tlsConn.HandshakeContext(ctx); err != nil {
13+
return err
14+
}
15+
if !cfg.InsecureSkipVerify {
16+
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
17+
return err
18+
}
19+
}
20+
return nil
21+
}

tls_handshake_116.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !go1.17
2+
// +build !go1.17
3+
4+
package websocket
5+
6+
import (
7+
"context"
8+
"crypto/tls"
9+
)
10+
11+
func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
12+
if err := tlsConn.Handshake(); err != nil {
13+
return err
14+
}
15+
if !cfg.InsecureSkipVerify {
16+
if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
17+
return err
18+
}
19+
}
20+
return nil
21+
}

trace.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

trace_17.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)