Skip to content

Commit 15656ac

Browse files
gstarikovybbus
andauthored
replaced *http.Client with HTTPClient interface (Do method) (#59)
Co-authored-by: Alexander Gehres <alexander.gehres@gmail.com>
1 parent ecb842f commit 15656ac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jsonrpc.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,14 @@ func (e *HTTPError) Error() string {
244244
return e.err.Error()
245245
}
246246

247+
// HTTPClient interface is provided to be used instead of http.Client (e.g. to overload redirect/ retry policy)
248+
type HTTPClient interface {
249+
Do(req *http.Request) (*http.Response, error)
250+
}
251+
247252
type rpcClient struct {
248253
endpoint string
249-
httpClient *http.Client
254+
httpClient HTTPClient
250255
customHeaders map[string]string
251256
allowUnknownFields bool
252257
defaultRequestID int
@@ -260,7 +265,7 @@ type rpcClient struct {
260265
//
261266
// AllowUnknownFields: allows the rpc response to contain fields that are not defined in the rpc response specification.
262267
type RPCClientOpts struct {
263-
HTTPClient *http.Client
268+
HTTPClient HTTPClient
264269
CustomHeaders map[string]string
265270
AllowUnknownFields bool
266271
DefaultRequestID int

0 commit comments

Comments
 (0)