Add util to set transport defaults

This commit is contained in:
Jordan Liggitt
2015-10-02 00:30:49 -04:00
parent 719cf5617e
commit 2a1286c8f2
5 changed files with 30 additions and 29 deletions

View File

@@ -18,6 +18,7 @@ package util
import (
"io"
"net/http"
"net/url"
"strings"
)
@@ -44,3 +45,20 @@ func IsProbableEOF(err error) bool {
}
return false
}
var defaultTransport = http.DefaultTransport.(*http.Transport)
// SetTransportDefaults applies the defaults from http.DefaultTransport
// for the Proxy, Dial, and TLSHandshakeTimeout fields if unset
func SetTransportDefaults(t *http.Transport) *http.Transport {
if t.Proxy == nil {
t.Proxy = defaultTransport.Proxy
}
if t.Dial == nil {
t.Dial = defaultTransport.Dial
}
if t.TLSHandshakeTimeout == 0 {
t.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout
}
return t
}