Reuse http transport

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

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

Loading…
Cancel
Save