@@ -9,40 +9,19 @@ package httpclient
99
1010import (
1111 "fmt"
12- "io"
1312 "net/http"
1413 "net/http/cookiejar"
15- "net/url"
1614 "time"
1715
1816 "github.com/deploymenttheory/go-api-http-client/concurrency"
1917 "go.uber.org/zap"
2018)
2119
22- // HTTPExecutor is an interface which wraps http.Client to allow mocking.
23- type HTTPExecutor interface {
24-
25- // Inherited
26- CloseIdleConnections ()
27- Do (req * http.Request ) (* http.Response , error )
28- Get (url string ) (resp * http.Response , err error )
29- Head (url string ) (resp * http.Response , err error )
30- Post (url string , contentType string , body io.Reader ) (resp * http.Response , err error )
31- PostForm (url string , data url.Values ) (resp * http.Response , err error )
32-
33- // Additional
34- SetCookieJar (jar http.CookieJar )
35- SetCookies (url * url.URL , cookies []* http.Cookie )
36- SetCustomTimeout (time.Duration )
37- Cookies (* url.URL ) []* http.Cookie
38- SetRedirectPolicy (* func (req * http.Request , via []* http.Request ) error )
39- }
40-
4120// Master struct/object
4221type Client struct {
4322 config * ClientConfig
4423 Integration * APIIntegration
45- http HTTPExecutor
24+ http * http. Client
4625 Sugar * zap.SugaredLogger
4726 Concurrency * concurrency.ConcurrencyHandler
4827}
@@ -100,7 +79,7 @@ type ClientConfig struct {
10079 // RetryEligiableRequests when false bypasses any retry logic for a simpler request flow.
10180 RetryEligiableRequests bool `json:"retry_eligiable_requests"`
10281
103- HTTPExecutor HTTPExecutor
82+ HTTPExecutor http. Client
10483}
10584
10685// BuildClient creates a new HTTP client with the provided configuration.
@@ -131,10 +110,10 @@ func (c *ClientConfig) Build() (*Client, error) {
131110 return nil , err
132111 }
133112
134- httpClient .SetCookieJar ( cookieJar )
113+ httpClient .Jar = cookieJar
135114
136115 if c .CustomRedirectPolicy != nil {
137- httpClient .SetRedirectPolicy ( c .CustomRedirectPolicy )
116+ httpClient .CheckRedirect = * c .CustomRedirectPolicy
138117 }
139118
140119 // TODO refactor concurrency
@@ -150,7 +129,7 @@ func (c *ClientConfig) Build() (*Client, error) {
150129
151130 client := & Client {
152131 Integration : & c .Integration ,
153- http : httpClient ,
132+ http : & httpClient ,
154133 config : c ,
155134 Sugar : c .Sugar ,
156135 Concurrency : concurrencyHandler ,
0 commit comments