Skip to content

Commit 5a1b7aa

Browse files
authored
Merge pull request #90 from erickearns/master
Make underlying httpClient configurable
2 parents 6df3e33 + 6ce72ca commit 5a1b7aa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func httpClient(ctx context.Context, addr string, namespace string, outs []inter
160160

161161
hreq.Header.Set("Content-Type", "application/json")
162162

163-
httpResp, err := _defaultHTTPClient.Do(hreq)
163+
httpResp, err := config.httpClient.Do(hreq)
164164
if err != nil {
165165
return clientResponse{}, &RPCConnectionError{err}
166166
}

options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jsonrpc
22

33
import (
4+
"net/http"
45
"reflect"
56
"time"
67

@@ -17,6 +18,8 @@ type Config struct {
1718
paramEncoders map[reflect.Type]ParamEncoder
1819
errors *Errors
1920

21+
httpClient *http.Client
22+
2023
noReconnect bool
2124
proxyConnFactory func(func() (*websocket.Conn, error)) func() (*websocket.Conn, error) // for testing
2225
}
@@ -31,6 +34,8 @@ func defaultConfig() Config {
3134
timeout: 30 * time.Second,
3235

3336
paramEncoders: map[reflect.Type]ParamEncoder{},
37+
38+
httpClient: _defaultHTTPClient,
3439
}
3540
}
3641

@@ -75,3 +80,9 @@ func WithErrors(es Errors) func(c *Config) {
7580
c.errors = &es
7681
}
7782
}
83+
84+
func WithHTTPClient(h *http.Client) func(c *Config) {
85+
return func(c *Config) {
86+
c.httpClient = h
87+
}
88+
}

0 commit comments

Comments
 (0)