Add a default handshake timeout of 5 seconds

This commit is contained in:
Pablo Carranza 2018-03-04 12:17:01 +01:00 committed by Gary Burd
parent e426f23f06
commit 196b8d0585
1 changed files with 5 additions and 2 deletions

View File

@ -41,6 +41,7 @@ func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufS
NetDial: func(net, addr string) (net.Conn, error) {
return netConn, nil
},
HandshakeTimeout: 5 * time.Second,
}
return d.Dial(u.String(), requestHeader)
}
@ -107,6 +108,7 @@ func hostPortNoPort(u *url.URL) (hostPort, hostNoPort string) {
// DefaultDialer is a dialer with all fields set to the default values.
var DefaultDialer = &Dialer{
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 5 * time.Second,
}
// Dial creates a new client connection. Use requestHeader to specify the
@ -123,6 +125,7 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
if d == nil {
d = &Dialer{
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 5 * time.Second,
}
}