Skip to content

Commit

Permalink
refactor!: allow providing custom http.Client (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgacsal committed Apr 14, 2023
1 parent 2be922e commit 104c0f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 8 additions & 9 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,17 @@ func NewClient(opts *Config) (*Client, error) {
// Jar: jar,
// Timeout: 0,
// }
transport := http.DefaultTransport
if opts.Transport != nil {
transport = opts.Transport
}

client.httpClient = &http.Client{
Transport: transport,
client.httpClient = opts.HTTPClient
if client.httpClient == nil {
client.httpClient = &http.Client{
Transport: http.DefaultTransport,
}
}

serverURL := DefaultServerURL
if opts.ServerURL != "" {
serverURL = opts.ServerURL
serverURL := opts.ServerURL
if serverURL == "" {
serverURL = DefaultServerURL
}
if !strings.HasSuffix(serverURL, "/") {
serverURL += "/"
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type Config struct {
Password string
AccessToken string
UserAgent string
Transport http.RoundTripper

HTTPClient *http.Client
}

func (c *Config) ReadFromEnvironment() {
Expand Down

0 comments on commit 104c0f4

Please sign in to comment.