@@ -155,6 +155,7 @@ type ClientConfig struct {
155155 CircuitBreakerTimeout time.Duration
156156 CircuitBreakerReadyToTrip circuit.GoBreakerReadyToTripFunc
157157 CircuitBreakerOnStateChange circuit.GoBreakerOnStateChangeFunc
158+ CustomHTTPClient * http.Client
158159}
159160
160161type ClientOption func (* Client )
@@ -304,6 +305,12 @@ func WithClientConfig(config *ClientConfig) ClientOption {
304305 }
305306}
306307
308+ func WithCustomHTTPClient (client * http.Client ) ClientOption {
309+ return func (c * Client ) {
310+ c .apiConfig .CustomHTTPClient = client
311+ }
312+ }
313+
307314func NewClient (opts ... ClientOption ) * Client {
308315 c := & Client {apiConfig : & ClientConfig {
309316 RetryInterval : defaultRetryInterval ,
@@ -328,12 +335,16 @@ func NewClient(opts ...ClientOption) *Client {
328335 circuit .WithGoBreakerReadyToTrip (c .apiConfig .CircuitBreakerReadyToTrip ),
329336 circuit .WithGoBreakerOnStateChange (c .apiConfig .CircuitBreakerOnStateChange ),
330337 )
338+ client := c .apiConfig .CustomHTTPClient
339+ if client == nil {
340+ client = & http.Client {
341+ Timeout : c .apiConfig .ConnectionTimeout ,
342+ }
343+ }
331344 httpClient := circuit .NewHTTPClient (
332345 circuit .WithHTTPRequestDoer (
333346 NewAPICall (
334- & http.Client {
335- Timeout : c .apiConfig .ConnectionTimeout ,
336- },
347+ client ,
337348 c .apiConfig ,
338349 )),
339350 circuit .WithCircuitBreaker (cb ),
0 commit comments