Merge pull request #260 from stevenroose/http-client-quorum

rpc: Support specifying HTTP client in RPC dialing
This commit is contained in:
Patrick Mylund Nielsen 2018-01-25 13:07:42 -05:00 committed by GitHub
commit 3719d61ee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -62,9 +62,10 @@ func (hc *httpConn) Close() error {
return nil
}
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
func DialHTTP(endpoint string) (*Client, error) {
req, err := http.NewRequest("POST", endpoint, nil)
// DialHTTPWithClient creates a new RPC clients that connection to an RPC server over HTTP
// using the provided HTTP Client.
func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error) {
req, err := http.NewRequest(http.MethodPost, endpoint, nil)
if err != nil {
return nil, err
}
@ -73,10 +74,15 @@ func DialHTTP(endpoint string) (*Client, error) {
initctx := context.Background()
return newClient(initctx, func(context.Context) (net.Conn, error) {
return &httpConn{client: new(http.Client), req: req, closed: make(chan struct{})}, nil
return &httpConn{client: client, req: req, closed: make(chan struct{})}, nil
})
}
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
func DialHTTP(endpoint string) (*Client, error) {
return DialHTTPWithClient(endpoint, new(http.Client))
}
func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error {
hc := c.writeConn.(*httpConn)
respBody, err := hc.doRequest(ctx, msg)