Skip to content

Commit

Permalink
Merge pull request #245 from bdwyertech/override-http-client
Browse files Browse the repository at this point in the history
Allow overriding http-client
  • Loading branch information
MarkGibbons authored Mar 25, 2023
2 parents a129f34 + 0f48b63 commit d9cc32a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ type Config struct {

// Proxy function to be used when making requests
Proxy func(*http.Request) (*url.URL, error)

// Pointer to an HTTP Client to use instead of the default
Client *http.Client
}

/*
Expand Down Expand Up @@ -239,11 +242,16 @@ func NewClient(cfg *Config) (*Client, error) {
ClientName: cfg.Name,
AuthenticationVersion: cfg.AuthenticationVersion,
},
client: &http.Client{
BaseURL: baseUrl,
}

if cfg.Client != nil {
c.client = cfg.Client
} else {
c.client = &http.Client{
Transport: tr,
Timeout: time.Duration(cfg.Timeout) * time.Second,
},
BaseURL: baseUrl,
}
}
c.IsWebuiKey = cfg.IsWebuiKey
c.ACLs = &ACLService{client: c}
Expand Down

0 comments on commit d9cc32a

Please sign in to comment.