From 5fe84373c76f444ff8bbbfd1285810b2a4be8fe3 Mon Sep 17 00:00:00 2001 From: fm Date: Sat, 4 Nov 2023 22:08:41 +0100 Subject: [PATCH] change parent to nil needed to provide compatibility with httpmock for testing. --- client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index d55e693..e8d1412 100644 --- a/client.go +++ b/client.go @@ -31,7 +31,7 @@ func NewClient(rawURL, schema string, headers map[string]string) *Client { t := transport{ header: http.Header{}, baseURL: *baseURL, - Parent: http.DefaultTransport, + Parent: nil, } c := Client{ @@ -164,5 +164,11 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) { } req.URL = t.baseURL.ResolveReference(req.URL) - return t.Parent.RoundTrip(req) + + // This is only needed with usage of httpmock in testing. It would be better to initialize + // t.Parent with http.DefaultTransport and then use t.Parent.RoundTrip(req) + if t.Parent != nil { + return t.Parent.RoundTrip(req) + } + return http.DefaultTransport.RoundTrip(req) }