Skip to content

Commit

Permalink
Improve client default timeout code
Browse files Browse the repository at this point in the history
- Remove duplicate code.
- Don't update deprecated functions.
  • Loading branch information
garyburd committed Mar 6, 2018
1 parent 8c40c0b commit 4835f71
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufS
NetDial: func(net, addr string) (net.Conn, error) {
return netConn, nil
},
HandshakeTimeout: 45 * time.Second,
}
return d.Dial(u.String(), requestHeader)
}
Expand Down Expand Up @@ -111,6 +110,9 @@ var DefaultDialer = &Dialer{
HandshakeTimeout: 45 * time.Second,
}

// nilDialer is dialer to use when receiver is nil.
var nilDialer Dialer = *DefaultDialer

// Dial creates a new client connection. Use requestHeader to specify the
// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie).
// Use the response.Header to get the selected subprotocol
Expand All @@ -123,10 +125,7 @@ var DefaultDialer = &Dialer{
func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {

if d == nil {
d = &Dialer{
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 45 * time.Second,
}
d = &nilDialer
}

challengeKey, err := generateChallengeKey()
Expand Down

0 comments on commit 4835f71

Please sign in to comment.