-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web3): add ability to pass different websocket endpoint #17387 (…
…#17556)
- Loading branch information
1 parent
bbc0de6
commit aa5e806
Showing
4 changed files
with
57 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {format as urlFormat, parse as urlParse} from 'url'; | ||
|
||
export function makeWebsocketUrl(endpoint: string) { | ||
let url = urlParse(endpoint); | ||
const useHttps = url.protocol === 'https:'; | ||
|
||
url.protocol = useHttps ? 'wss:' : 'ws:'; | ||
url.host = ''; | ||
|
||
// Only shift the port by +1 as a convention for ws(s) only if given endpoint | ||
// is explictly specifying the endpoint port (HTTP-based RPC), assuming | ||
// we're directly trying to connect to solana-validator's ws listening port. | ||
// When the endpoint omits the port, we're connecting to the protocol | ||
// default ports: http(80) or https(443) and it's assumed we're behind a reverse | ||
// proxy which manages WebSocket upgrade and backend port redirection. | ||
if (url.port !== null) { | ||
url.port = String(Number(url.port) + 1); | ||
} | ||
return urlFormat(url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters