From 4fe6bfc0c06028108a0674d75aa5f2303a31d06e Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Fri, 13 Oct 2023 12:24:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20allow=20the=20override=20o?= =?UTF-8?q?f=20the=20http=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/http/http.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/http/http.go b/internal/http/http.go index f602ab9..0f18afe 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -35,12 +35,37 @@ func NewHttpClient(opts ...option.ClientOption) (*http.Client, string, error) { return nil, "", err } - trans, err := newTransport(http.DefaultTransport, settings) + var transport http.RoundTripper + if settings.HTTPClient != nil { + transport = settings.HTTPClient.Transport + } + + if transport == nil { + transport = http.DefaultTransport + } + + trans, err := newTransport(transport, settings) if err != nil { return nil, "", err } - return &http.Client{Transport: trans}, settings.Endpoint, nil + client := &http.Client{ + Transport: trans, + } + + if settings.HTTPClient != nil && settings.HTTPClient.Timeout > 0 { + client.Timeout = settings.HTTPClient.Timeout + } + + if settings.HTTPClient != nil && settings.HTTPClient.CheckRedirect != nil { + client.CheckRedirect = settings.HTTPClient.CheckRedirect + } + + if settings.HTTPClient != nil && settings.HTTPClient.Jar != nil { + client.Jar = settings.HTTPClient.Jar + } + + return client, settings.Endpoint, nil } // newTransport creates a new http.RoundTripper based on the given options.