fix: use Node.js https agent when endpoint uses https (#12692)
This commit is contained in:
@@ -505,8 +505,8 @@ type ConfirmedBlock = {
|
||||
}>,
|
||||
};
|
||||
|
||||
function createRpcRequest(url): RpcRequest {
|
||||
const agentManager = new AgentManager();
|
||||
function createRpcRequest(url: string, useHttps: boolean): RpcRequest {
|
||||
const agentManager = new AgentManager(useHttps);
|
||||
const server = jayson(async (request, callback) => {
|
||||
const agent = agentManager.requestStart();
|
||||
const options = {
|
||||
@@ -1453,8 +1453,9 @@ export class Connection {
|
||||
*/
|
||||
constructor(endpoint: string, commitment: ?Commitment) {
|
||||
let url = urlParse(endpoint);
|
||||
const useHttps = url.protocol === 'https:';
|
||||
|
||||
this._rpcRequest = createRpcRequest(url.href);
|
||||
this._rpcRequest = createRpcRequest(url.href, useHttps);
|
||||
this._commitment = commitment;
|
||||
this._blockhashInfo = {
|
||||
recentBlockhash: null,
|
||||
@@ -1463,7 +1464,7 @@ export class Connection {
|
||||
simulatedSignatures: [],
|
||||
};
|
||||
|
||||
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
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
|
||||
|
Reference in New Issue
Block a user