Update go-cleanhttp dependency.

Probably fixes #867
This commit is contained in:
Jeff Mitchell 2015-12-17 15:08:19 -05:00
parent f6ff39ffb0
commit dfffe5cd15
2 changed files with 14 additions and 2 deletions

2
Godeps/Godeps.json generated
View File

@ -157,7 +157,7 @@
},
{
"ImportPath": "github.com/hashicorp/go-cleanhttp",
"Rev": "5df5ddc69534f1a4697289f1dca2193fbb40213f"
"Rev": "ce617e79981a8fff618bb643d155133a8f38db96"
},
{
"ImportPath": "github.com/hashicorp/go-multierror",

View File

@ -3,13 +3,14 @@ package cleanhttp
import (
"net"
"net/http"
"runtime"
"time"
)
// DefaultTransport returns a new http.Transport with the same default values
// as http.DefaultTransport
func DefaultTransport() *http.Transport {
return &http.Transport{
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
@ -17,6 +18,8 @@ func DefaultTransport() *http.Transport {
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
SetTransportFinalizer(transport)
return transport
}
// DefaultClient returns a new http.Client with the same default values as
@ -26,3 +29,12 @@ func DefaultClient() *http.Client {
Transport: DefaultTransport(),
}
}
// SetTransportFinalizer sets a finalizer on the transport to ensure that
// idle connections are closed prior to garbage collection; otherwise
// these may leak
func SetTransportFinalizer(transport *http.Transport) {
runtime.SetFinalizer(&transport, func(t **http.Transport) {
(*t).CloseIdleConnections()
})
}