// 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 }
// SetOldTransportDefaults applies the defaults from http.DefaultTransport // for the Proxy, Dial, and TLSHandshakeTimeout fields if unset func SetOldTransportDefaults(t *http.Transport) *http.Transport { if t.Proxy == nil || isDefault(t.Proxy) { // http.ProxyFromEnvironment doesn't respect CIDRs and that makes it impossible to exclude things like pod and service IPs from proxy settings // ProxierWithNoProxyCIDR allows CIDR rules in NO_PROXY t.Proxy = NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment) } if t.Dial == nil { t.Dial = defaultTransport.Dial } if t.TLSHandshakeTimeout == 0 { t.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout } return t }
func newHttpClient(config *Config) *http.Client { transport := new(http.Transport) if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok { transport.Proxy = defaultTransport.Proxy transport.Dial = defaultTransport.Dial transport.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout } if config.ProxyHost != "" { host := config.ProxyHost if config.ProxyPort > 0 { host += ":" + strconv.Itoa(config.ProxyPort) } proxyUrl, err := url.Parse(util.HostToURL(host, "http")) if err != nil { panic(err) } transport.Proxy = http.ProxyURL(proxyUrl) } /* if c.ConnectionTimeout > 0 { transport.TLSHandshakeTimeout = c.ConnectionTimeout } */ if config.MaxConnections > 0 { transport.MaxIdleConnsPerHost = config.MaxConnections } return &http.Client{ Transport: transport, Timeout: config.Timeout, } }
// Transport returns an http.RoundTripper with the correct timeouts func (ci *ConfigInfo) Transport() http.RoundTripper { noTransport.Do(func() { // Start with a sensible set of defaults then override. // This also means we get new stuff when it gets added to go t := new(http.Transport) setDefaults(t, http.DefaultTransport.(*http.Transport)) t.Proxy = http.ProxyFromEnvironment t.MaxIdleConnsPerHost = 4 * (ci.Checkers + ci.Transfers + 1) t.TLSHandshakeTimeout = ci.ConnectTimeout t.ResponseHeaderTimeout = ci.Timeout t.TLSClientConfig = &tls.Config{InsecureSkipVerify: ci.InsecureSkipVerify} t.DisableCompression = *noGzip // Set in http_old.go initTransport // t.Dial // Set in http_new.go initTransport // t.DialContext // t.IdelConnTimeout // t.ExpectContinueTimeout ci.initTransport(t) // Wrap that http.Transport in our own transport transport = NewTransport(t, ci.DumpHeaders, ci.DumpBodies) }) return transport }