Permalink
Browse files

Include connect timeout in HTTP timeouts.

Maximum 1 minute (which is a rather long time).
  • Loading branch information...
1 parent 3ee492e commit 1b492e90499cd2a097d5ff6a2f150897240d7217 @dustin dustin committed Sep 29, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 timeout.go
View
@@ -48,11 +48,15 @@ func (tc *timeoutConn) SetWriteDeadline(t time.Time) error {
}
func TimeoutTransport(timeout time.Duration) *http.Transport {
+ dt := timeout
+ if dt > time.Minute {
+ dt = time.Minute
+ }
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
Dial: func(n, addr string) (net.Conn, error) {
- conn, err := net.Dial(n, addr)
+ conn, err := net.DialTimeout(n, addr, dt)
return &timeoutConn{conn, timeout}, err
},
}

0 comments on commit 1b492e9

Please sign in to comment.