Skip to content

Commit 4835f71

Browse files
committed
Improve client default timeout code
- Remove duplicate code. - Don't update deprecated functions.
1 parent 8c40c0b commit 4835f71

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufS
4141
NetDial: func(net, addr string) (net.Conn, error) {
4242
return netConn, nil
4343
},
44-
HandshakeTimeout: 45 * time.Second,
4544
}
4645
return d.Dial(u.String(), requestHeader)
4746
}
@@ -111,6 +110,9 @@ var DefaultDialer = &Dialer{
111110
HandshakeTimeout: 45 * time.Second,
112111
}
113112

113+
// nilDialer is dialer to use when receiver is nil.
114+
var nilDialer Dialer = *DefaultDialer
115+
114116
// Dial creates a new client connection. Use requestHeader to specify the
115117
// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie).
116118
// Use the response.Header to get the selected subprotocol
@@ -123,10 +125,7 @@ var DefaultDialer = &Dialer{
123125
func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
124126

125127
if d == nil {
126-
d = &Dialer{
127-
Proxy: http.ProxyFromEnvironment,
128-
HandshakeTimeout: 45 * time.Second,
129-
}
128+
d = &nilDialer
130129
}
131130

132131
challengeKey, err := generateChallengeKey()

0 commit comments

Comments
 (0)