From aac85a14f0a79b37e87f41b6fb66a39d7131b08b Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 22 Jun 2017 20:56:57 +0200 Subject: [PATCH] httpDialer accepts no prefix or http:// as tcp:// --- rpc/lib/client/http_client.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/rpc/lib/client/http_client.go b/rpc/lib/client/http_client.go index 12cf793a6..755c3e79c 100644 --- a/rpc/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -13,7 +13,6 @@ import ( "github.com/pkg/errors" types "github.com/tendermint/tendermint/rpc/lib/types" - cmn "github.com/tendermint/tmlibs/common" ) // HTTPClient is a common interface for JSONRPCClient and URIClient. @@ -23,13 +22,23 @@ type HTTPClient interface { // TODO: Deprecate support for IP:PORT or /path/to/socket func makeHTTPDialer(remoteAddr string) (string, func(string, string) (net.Conn, error)) { - parts := strings.SplitN(remoteAddr, "://", 2) var protocol, address string - if len(parts) != 2 { - cmn.PanicSanity(fmt.Sprintf("Expected fully formed listening address, including the tcp:// or unix:// prefix, given %s", remoteAddr)) - } else { + if len(parts) == 1 { + // default to tcp if nothing specified + protocol, address = "tcp", remoteAddr + } else if len(parts) == 2 { protocol, address = parts[0], parts[1] + } else { + // return a invalid message + msg := fmt.Sprintf("Invalid addr: %s", remoteAddr) + return msg, func(_ string, _ string) (net.Conn, error) { + return nil, errors.New(msg) + } + } + // accept http as an alias for tcp + if protocol == "http" { + protocol = "tcp" } trimmedAddress := strings.Replace(address, "/", ".", -1) // replace / with . for http requests (dummy domain)