Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rpc "no port provided" error by backporting #1528

Draft
wants to merge 5 commits into
base: v0.34.x-celestia
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions rpc/jsonrpc/client/http_json_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"net"
"net/http"
"net/url"
"regexp"
"strings"

cmtsync "github.com/tendermint/tendermint/libs/sync"
Expand All @@ -24,7 +25,7 @@
protoUNIX = "unix"
)

//-------------------------------------------------------------
var endsWithPortPattern = regexp.MustCompile(`:[0-9]+$`)

Check failure on line 28 in rpc/jsonrpc/client/http_json_client.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var `endsWithPortPattern` is unused (unused)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golangci-lint complains here


// Parsed URL structure
type parsedURL struct {
Expand Down Expand Up @@ -87,13 +88,27 @@
return strings.ReplaceAll(u.GetHostWithPath(), "/", ".")
}

// GetDialAddress returns the endpoint to dial for the parsed URL
// GetDialAddress returns the endpoint to dial for the parsed URL.
func (u parsedURL) GetDialAddress() string {
// if it's not a unix socket we return the host, example: localhost:443
if !u.isUnixSocket {
return u.Host
}
// otherwise we return the path of the unix socket, ex /tmp/socket
host := u.Host
// Check if the host already includes a port
_, _, err := net.SplitHostPort(host)
if err != nil {
// Add the default port based on the scheme
switch u.Scheme {
case protoHTTP, protoWS:
host = net.JoinHostPort(host, "80")
case protoHTTPS, protoWSS:
host = net.JoinHostPort(host, "443")
default:
// Handle unsupported schemes explicitly
panic("unsupported scheme: " + u.Scheme)
}
}
return host
}
// For Unix sockets, return the full path
return u.GetHostWithPath()
}

Expand Down
19 changes: 16 additions & 3 deletions rpc/jsonrpc/client/http_json_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,41 @@ func Test_parsedURL(t *testing.T) {
}

tests := map[string]test{
"http endpoint": {
url: "http://example.com",
expectedURL: "http://example.com",
expectedHostWithPath: "example.com",
expectedDialAddress: "example.com:80",
},

"http endpoint with port": {
url: "http://example.com:8080",
expectedURL: "http://example.com:8080",
expectedHostWithPath: "example.com:8080",
expectedDialAddress: "example.com:8080",
},
"unix endpoint": {
url: "unix:///tmp/test",
expectedURL: "unix://.tmp.test",
expectedHostWithPath: "/tmp/test",
expectedDialAddress: "/tmp/test",
},

"http endpoint": {
"https endpoint": {
url: "https://example.com",
expectedURL: "https://example.com",
expectedHostWithPath: "example.com",
expectedDialAddress: "example.com",
},

"http endpoint with port": {
"https endpoint with port": {
url: "https://example.com:8080",
expectedURL: "https://example.com:8080",
expectedHostWithPath: "example.com:8080",
expectedDialAddress: "example.com:8080",
},

"http path routed endpoint": {
"https path routed endpoint": {
url: "https://example.com:8080/rpc",
expectedURL: "https://example.com:8080/rpc",
expectedHostWithPath: "example.com:8080/rpc",
Expand Down
Loading