Skip to content

Commit

Permalink
Include connect timeout in HTTP timeouts.
Browse files Browse the repository at this point in the history
Maximum 1 minute (which is a rather long time).
  • Loading branch information
dustin committed Sep 29, 2012
1 parent 3ee492e commit 1b492e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion timeout.go
Expand Up @@ -48,11 +48,15 @@ func (tc *timeoutConn) SetWriteDeadline(t time.Time) error {
} }


func TimeoutTransport(timeout time.Duration) *http.Transport { func TimeoutTransport(timeout time.Duration) *http.Transport {
dt := timeout
if dt > time.Minute {
dt = time.Minute
}
return &http.Transport{ return &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true, DisableKeepAlives: true,
Dial: func(n, addr string) (net.Conn, error) { 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 return &timeoutConn{conn, timeout}, err
}, },
} }
Expand Down

0 comments on commit 1b492e9

Please sign in to comment.