Add WithTransport

Signed-off-by: Paulo Gomes <pjbgf@linux.com>
pull/10668/head
Paulo Gomes 4 years ago
parent 12f1bc0acd
commit 69d1e90b40
No known key found for this signature in database
GPG Key ID: 9995233870E99BEE

@ -18,6 +18,7 @@ package getter
import ( import (
"bytes" "bytes"
"net/http"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -43,6 +44,7 @@ type options struct {
version string version string
registryClient *registry.Client registryClient *registry.Client
timeout time.Duration timeout time.Duration
transport *http.Transport
} }
// Option allows specifying various settings configurable by the user for overriding the defaults // Option allows specifying various settings configurable by the user for overriding the defaults
@ -119,6 +121,12 @@ func WithUntar() Option {
} }
} }
func WithTransport(transport *http.Transport) Option {
return func(opts *options) {
opts.transport = transport
}
}
// Getter is an interface to support GET to the specified URL. // Getter is an interface to support GET to the specified URL.
type Getter interface { type Getter interface {
// Get file content by url string // Get file content by url string

@ -106,10 +106,17 @@ func NewHTTPGetter(options ...Option) (Getter, error) {
} }
func (g *HTTPGetter) httpClient() (*http.Client, error) { func (g *HTTPGetter) httpClient() (*http.Client, error) {
transport := &http.Transport{ var transport *http.Transport
DisableCompression: true,
Proxy: http.ProxyFromEnvironment, if g.opts.transport == nil {
transport = &http.Transport{
DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
}
} else {
transport = g.opts.transport
} }
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 {

Loading…
Cancel
Save