mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-30 13:11:38 +00:00
rpc: allow using a custom http client in rpc client (#3779)
fixes #2010 * allow using a custom http client in rpc client * add tests and fix bug * fix confusion between remote and address * parse remote inside NewJSONRPCClientWithHTTPClient * cleanups * add warnings * add changelog entry * Update CHANGELOG_PENDING.md Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -84,8 +85,19 @@ var _ rpcClient = (*baseRPCClient)(nil)
|
||||
|
||||
// NewHTTP takes a remote endpoint in the form <protocol>://<host>:<port> and
|
||||
// the websocket path (which always seems to be "/websocket")
|
||||
// The function panics if the provided remote is invalid.<Paste>
|
||||
func NewHTTP(remote, wsEndpoint string) *HTTP {
|
||||
rc := rpcclient.NewJSONRPCClient(remote)
|
||||
httpClient := rpcclient.DefaultHTTPClient(remote)
|
||||
return NewHTTPWithClient(remote, wsEndpoint, httpClient)
|
||||
}
|
||||
|
||||
// NewHTTPWithClient allows for setting a custom http client. See NewHTTP
|
||||
// The function panics if the provided client is nil or remote is invalid.
|
||||
func NewHTTPWithClient(remote, wsEndpoint string, client *http.Client) *HTTP {
|
||||
if client == nil {
|
||||
panic("nil http.Client provided")
|
||||
}
|
||||
rc := rpcclient.NewJSONRPCClientWithHTTPClient(remote, client)
|
||||
cdc := rc.Codec()
|
||||
ctypes.RegisterAmino(cdc)
|
||||
rc.SetCodec(cdc)
|
||||
|
Reference in New Issue
Block a user