@@ -9,40 +9,19 @@ package httpclient
9
9
10
10
import (
11
11
"fmt"
12
- "io"
13
12
"net/http"
14
13
"net/http/cookiejar"
15
- "net/url"
16
14
"time"
17
15
18
16
"github.com/deploymenttheory/go-api-http-client/concurrency"
19
17
"go.uber.org/zap"
20
18
)
21
19
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
-
41
20
// Master struct/object
42
21
type Client struct {
43
22
config * ClientConfig
44
23
Integration * APIIntegration
45
- http HTTPExecutor
24
+ http * http. Client
46
25
Sugar * zap.SugaredLogger
47
26
Concurrency * concurrency.ConcurrencyHandler
48
27
}
@@ -100,7 +79,7 @@ type ClientConfig struct {
100
79
// RetryEligiableRequests when false bypasses any retry logic for a simpler request flow.
101
80
RetryEligiableRequests bool `json:"retry_eligiable_requests"`
102
81
103
- HTTPExecutor HTTPExecutor
82
+ HTTPExecutor http. Client
104
83
}
105
84
106
85
// BuildClient creates a new HTTP client with the provided configuration.
@@ -131,10 +110,10 @@ func (c *ClientConfig) Build() (*Client, error) {
131
110
return nil , err
132
111
}
133
112
134
- httpClient .SetCookieJar ( cookieJar )
113
+ httpClient .Jar = cookieJar
135
114
136
115
if c .CustomRedirectPolicy != nil {
137
- httpClient .SetRedirectPolicy ( c .CustomRedirectPolicy )
116
+ httpClient .CheckRedirect = * c .CustomRedirectPolicy
138
117
}
139
118
140
119
// TODO refactor concurrency
@@ -150,7 +129,7 @@ func (c *ClientConfig) Build() (*Client, error) {
150
129
151
130
client := & Client {
152
131
Integration : & c .Integration ,
153
- http : httpClient ,
132
+ http : & httpClient ,
154
133
config : c ,
155
134
Sugar : c .Sugar ,
156
135
Concurrency : concurrencyHandler ,
0 commit comments