Skip to content

Commit

Permalink
Reuse http transport
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Fehr <matthias@monostream.com>
(cherry picked from commit aa33f4f)
  • Loading branch information
matthiasfehr authored and mattfarina committed Apr 8, 2022
1 parent 5cb9af4 commit 6c5adf1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pkg/getter/httpgetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}

Expand Down

0 comments on commit 6c5adf1

Please sign in to comment.