10 // DefaultTransport returns a new http.Transport with the same default values
11 // as http.DefaultTransport
12 func DefaultTransport() *http.Transport {
13 transport := &http.Transport{
14 Proxy: http.ProxyFromEnvironment,
16 Timeout: 30 * time.Second,
17 KeepAlive: 30 * time.Second,
19 TLSHandshakeTimeout: 10 * time.Second,
21 SetTransportFinalizer(transport)
25 // DefaultClient returns a new http.Client with the same default values as
26 // http.Client, but with a non-shared Transport
27 func DefaultClient() *http.Client {
29 Transport: DefaultTransport(),
33 // SetTransportFinalizer sets a finalizer on the transport to ensure that
34 // idle connections are closed prior to garbage collection; otherwise
36 func SetTransportFinalizer(transport *http.Transport) {
37 runtime.SetFinalizer(&transport, func(t **http.Transport) {
38 (*t).CloseIdleConnections()