Browse Source

httpDialer accepts no prefix or http:// as tcp://

pull/552/head
Ethan Frey 8 years ago
parent
commit
aac85a14f0
1 changed files with 14 additions and 5 deletions
  1. +14
    -5
      rpc/lib/client/http_client.go

+ 14
- 5
rpc/lib/client/http_client.go View File

@ -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)


Loading…
Cancel
Save