Skip to content

Commit

Permalink
change parent to nil
Browse files Browse the repository at this point in the history
needed to provide compatibility with httpmock for testing.
  • Loading branch information
Fritte795 committed Nov 4, 2023
1 parent ec993ac commit 5fe8437
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

0 comments on commit 5fe8437

Please sign in to comment.