Skip to content

Commit

Permalink
⭐️ allow the override of the http client (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Nov 1, 2023
1 parent 9988d49 commit 218731b
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 218731b

Please sign in to comment.