Skip to content

Commit 3719d61

Browse files
authored
Merge pull request ethereum#260 from stevenroose/http-client-quorum
rpc: Support specifying HTTP client in RPC dialing
2 parents f27f7b3 + 1eb5e2d commit 3719d61

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

rpc/http.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ func (hc *httpConn) Close() error {
6262
return nil
6363
}
6464

65-
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
66-
func DialHTTP(endpoint string) (*Client, error) {
67-
req, err := http.NewRequest("POST", endpoint, nil)
65+
// DialHTTPWithClient creates a new RPC clients that connection to an RPC server over HTTP
66+
// using the provided HTTP Client.
67+
func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error) {
68+
req, err := http.NewRequest(http.MethodPost, endpoint, nil)
6869
if err != nil {
6970
return nil, err
7071
}
@@ -73,10 +74,15 @@ func DialHTTP(endpoint string) (*Client, error) {
7374

7475
initctx := context.Background()
7576
return newClient(initctx, func(context.Context) (net.Conn, error) {
76-
return &httpConn{client: new(http.Client), req: req, closed: make(chan struct{})}, nil
77+
return &httpConn{client: client, req: req, closed: make(chan struct{})}, nil
7778
})
7879
}
7980

81+
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
82+
func DialHTTP(endpoint string) (*Client, error) {
83+
return DialHTTPWithClient(endpoint, new(http.Client))
84+
}
85+
8086
func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error {
8187
hc := c.writeConn.(*httpConn)
8288
respBody, err := hc.doRequest(ctx, msg)

0 commit comments

Comments
 (0)