8000 jsonrpc should respect HTTP(S) default port number · Issue #1902 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jsonrpc should respect HTTP(S) default port number #1902

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

Closed
gibson042 opened this issue Dec 28, 2023 · 0 comments · Fixed by #1903
Closed

jsonrpc should respect HTTP(S) default port number #1902

gibson042 opened this issue Dec 28, 2023 · 0 comments · Fixed by #1903
Labels
enhancement New feature or request rpc
Milestone

Comments

@gibson042
Copy link
Contributor
gibson042 commented Dec 28, 2023

Feature Request

Summary

RPC clients should infer an unspecified port number from the HTTP(S) default when applicable.

Problem Definition

Currently, the destination of every network-based RPC server must be specified with a URL including an explicit host port number (e.g., Cosmos SDK --node tcp://localhost:26657). But the scheme part of such URLs can be e.g. "http" or "https", which imply a default port number (respectively, 80 or 443). MakeHTTPDialer should respect those defaults, rather than causing behavior like this:

$ gaiad status --node https://cosmos-rpc.publicnode.com:443/
{"NodeInfo":{"protocol_version":{"p2p":"8","block":"11","app":"0"},"id":"821fa0f7ce74a211c5f5ec93cc6cc301564b92b6","listen_addr":"0.0.0.0:26656","network":"cosmoshub-4","version":"0.34.29","channels":"40202122233038606100","moniker":"Tendermint","other":{"tx_index":"on","rpc_address":"tcp://0.0.0.0:26657"}},"SyncInfo":{"latest_block_hash":"AA09142D55E38A406E5C3817FC03C2AE44832482FDBB5C311605130821D93AEC","latest_app_hash":"666EDA4B2A1F73BA5AB51D9F9AEC9E3489467DCF2199EB627FDAA156775D9DC6","latest_block_height":"18478442","latest_block_time":"2023-12-28T16:20:02.402318913Z","earliest_block_hash":"750D1D6B57311ACF430A243619DCFE4346EC4662FC4BEC83DE5A950856F10AB3","earliest_app_hash":"8C837EC300BC42DD737FF0C20D3A3AE689AC221C7DE127D4376616D3A574275A","earliest_block_height":"17875364","earliest_block_time":"2023-11-16T07:58:57.340253339Z","catching_up":false},"ValidatorInfo":{"Address":"0000000000000000000000000000000000000000","PubKey":{"type":"tendermint/PubKeySecp256k1","value":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"},"VotingPower":"0"}}
$ gaiad status --node https://cosmos-rpc.publicnode.com/
Error: post failed: Post "https://cosmos-rpc.publicnode.com/": dial tcp: address cosmos-rpc.publicnode.com: missing port in address

Proposal

Update jsonrpc to use port 80 when scheme is "http" and no port number is specified and port 443 when scheme is "https" and no port number is specified, in accordance with RFC 9110.

Suggestion:

 // 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 it's not a unix socket we return the host with port, example: localhost:443
 	if !u.isUnixSocket {
+		hasPort, err := regexp.MatchString(`:[0-9]+$`, u.Host)
+		if err == nil && !hasPort {
+			if u.Scheme == protoHTTP || u.Scheme == protoWS {
+				return u.Host + `:80`
+			} else if u.Scheme == protoHTTPS || u.scheme == protoWSS {
+				return u.Host + `:443`
+			}
+		}
 		return u.Host
 	}
 	// otherwise we return the path of the unix socket, ex /tmp/socket
 	return u.GetHostWithPath()
 }
@gibson042 gibson042 added enhancement New feature or request needs-triage This issue/PR has not yet been triaged by the team. labels Dec 28, 2023
gibson042 added a commit to gibson042/cometbft that referenced this issue Dec 28, 2023
gibson042 added a commit to gibson042/cometbft that referenced this issue Dec 28, 2023
@melekes melekes added rpc and removed needs-triage This issue/PR has not yet been triaged by the team. labels Jan 3, 2024
@melekes melekes moved this from Todo to Ready for Review in CometBFT 2023 Jan 3, 2024
@adizere adizere added this to the 2024-Q1 milestone Jan 16, 2024
@adizere adizere added this to CometBFT Jan 16, 2024
@github-project-automation github-project-automation bot moved this to Todo in CometBFT Jan 16, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 16, 2024
…t port (#1903)

Closes #1902

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments
@github-project-automation github-project-automation bot moved this from Todo to Done in CometBFT Jan 16, 2024
mergify bot pushed a commit that referenced this issue Jan 16, 2024
…t port (#1903)

Closes #1902

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments

(cherry picked from commit 9c9ffba)
mergify bot pushed a commit that referenced this issue Jan 16, 2024
…t port (#1903)

Closes #1902

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments

(cherry picked from commit 9c9ffba)

# Conflicts:
#	rpc/jsonrpc/client/http_json_client_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rpc
Projects
No open projects
Status: Done
Status: Ready for Review
Development

Successfully merging a pull request may close this issue.

3 participants
0