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:
gracenoah
2019-09-05 16:13:22 +03:00
committed by Anton Kaliaev
parent 72285115ec
commit aa721b972f
5 changed files with 118 additions and 28 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
)
@ -41,6 +42,23 @@ func GetClients() []client.Client {
}
}
func TestNilCustomHTTPClient(t *testing.T) {
require.Panics(t, func() {
client.NewHTTPWithClient("http://example.com", "/websocket", nil)
})
require.Panics(t, func() {
rpcclient.NewJSONRPCClientWithHTTPClient("http://example.com", nil)
})
}
func TestCustomHTTPClient(t *testing.T) {
remote := rpctest.GetConfig().RPC.ListenAddress
c := client.NewHTTPWithClient(remote, "/websocket", http.DefaultClient)
status, err := c.Status()
require.NoError(t, err)
require.NotNil(t, status)
}
func TestCorsEnabled(t *testing.T) {
origin := rpctest.GetConfig().RPC.CORSAllowedOrigins[0]
remote := strings.Replace(rpctest.GetConfig().RPC.ListenAddress, "tcp", "http", -1)