Reuse http transport

Signed-off-by: Matthias Fehr <matthias@monostream.com>
pull/10568/head
Matthias Fehr 2 years ago
parent c137bfb68b
commit aa33f4fdd8

@ -31,7 +31,8 @@ import (
// HTTPGetter is the default HTTP(/S) backend handler
type HTTPGetter struct {
opts options
opts options
transport *http.Transport
}
// Get performs a Get from repo.Getter and returns the body.
@ -106,10 +107,13 @@ func NewHTTPGetter(options ...Option) (Getter, error) {
}
func (g *HTTPGetter) httpClient() (*http.Client, error) {
transport := &http.Transport{
DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
if g.transport == nil {
g.transport = &http.Transport{
DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
}
}
if (g.opts.certFile != "" && g.opts.keyFile != "") || g.opts.caFile != "" {
tlsConf, err := tlsutil.NewClientTLS(g.opts.certFile, g.opts.keyFile, g.opts.caFile)
if err != nil {
@ -123,21 +127,21 @@ func (g *HTTPGetter) httpClient() (*http.Client, error) {
}
tlsConf.ServerName = sni
transport.TLSClientConfig = tlsConf
g.transport.TLSClientConfig = tlsConf
}
if g.opts.insecureSkipVerifyTLS {
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{
if g.transport.TLSClientConfig == nil {
g.transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
} else {
transport.TLSClientConfig.InsecureSkipVerify = true
g.transport.TLSClientConfig.InsecureSkipVerify = true
}
}
client := &http.Client{
Transport: transport,
Transport: g.transport,
Timeout: g.opts.timeout,
}

Loading…
Cancel
Save