Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit aa33f4f

Browse files
committed
Reuse http transport
Signed-off-by: Matthias Fehr <matthias@monostream.com>
1 parent c137bfb commit aa33f4f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkg/getter/httpgetter.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import (
3131

3232
// HTTPGetter is the default HTTP(/S) backend handler
3333
type HTTPGetter struct {
34-
opts options
34+
opts options
35+
transport *http.Transport
3536
}
3637

3738
// Get performs a Get from repo.Getter and returns the body.
@@ -106,10 +107,13 @@ func NewHTTPGetter(options ...Option) (Getter, error) {
106107
}
107108

108109
func (g *HTTPGetter) httpClient() (*http.Client, error) {
109-
transport := &http.Transport{
110-
DisableCompression: true,
111-
Proxy: http.ProxyFromEnvironment,
110+
if g.transport == nil {
111+
g.transport = &http.Transport{
112+
DisableCompression: true,
113+
Proxy: http.ProxyFromEnvironment,
114+
}
112115
}
116+
113117
if (g.opts.certFile != "" && g.opts.keyFile != "") || g.opts.caFile != "" {
114118
tlsConf, err := tlsutil.NewClientTLS(g.opts.certFile, g.opts.keyFile, g.opts.caFile)
115119
if err != nil {
@@ -123,21 +127,21 @@ func (g *HTTPGetter) httpClient() (*http.Client, error) {
123127
}
124128
tlsConf.ServerName = sni
125129

126-
transport.TLSClientConfig = tlsConf
130+
g.transport.TLSClientConfig = tlsConf
127131
}
128132

129133
if g.opts.insecureSkipVerifyTLS {
130-
if transport.TLSClientConfig == nil {
131-
transport.TLSClientConfig = &tls.Config{
134+
if g.transport.TLSClientConfig == nil {
135+
g.transport.TLSClientConfig = &tls.Config{
132136
InsecureSkipVerify: true,
133137
}
134138
} else {
135-
transport.TLSClientConfig.InsecureSkipVerify = true
139+
g.transport.TLSClientConfig.InsecureSkipVerify = true
136140
}
137141
}
138142

139143
client := &http.Client{
140-
Transport: transport,
144+
Transport: g.transport,
141145
Timeout: g.opts.timeout,
142146
}
143147

0 commit comments

Comments
 (0)