Skip to content

Commit

Permalink
Improve isTLSAlready check
Browse files Browse the repository at this point in the history
All conn implementations having a Handshake() error method are now seen
as a TLS conn and aren't wrapped in another tls.Client.
  • Loading branch information
erikdubbelboer committed Sep 3, 2022
1 parent 404c8a8 commit 2f1e949
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,11 @@ func dialAddr(addr string, dial DialFunc, dialDualStack, isTLS bool, tlsConfig *
if conn == nil {
panic("BUG: DialFunc returned (nil, nil)")
}
_, isTLSAlready := conn.(*tls.Conn)

// We assume that any conn that has the Handshake() method is a TLS conn already.
// This doesn't cover just tls.Conn but also other TLS implementations.
_, isTLSAlready := conn.(interface{ Handshake() error })

if isTLS && !isTLSAlready {
if timeout == 0 {
return tls.Client(conn, tlsConfig), nil
Expand Down

0 comments on commit 2f1e949

Please sign in to comment.