diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index af4ec62a1d7664..162a9374f3f670 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -1452,45 +1452,45 @@ function createRpcClient( customFetch?: FetchFn, fetchMiddleware?: FetchMiddleware, disableRetryOnRateLimit?: boolean, - agentOverride?: HttpAgent | HttpsAgent | false, + httpAgent?: HttpAgent | HttpsAgent | false, ): RpcClient { const fetch = customFetch ? customFetch : fetchImpl; let agentManager: | {requestEnd(): void; requestStart(): HttpAgent | HttpsAgent} | undefined; if (process.env.BROWSER) { - if (agentOverride != null) { + if (httpAgent != null) { console.warn( - 'You have supplied an `agentOverride` when creating a `Connection` in a browser ' + - 'environment. It has been ignored; `agentOverride` is only used in Node environments.', + 'You have supplied an `httpAgent` when creating a `Connection` in a browser environment.' + + 'It has been ignored; `httpAgent` is only used in Node environments.', ); } } else { - if (agentOverride == null) { + if (httpAgent == null) { if (process.env.NODE_ENV !== 'test') { agentManager = new AgentManager( url.startsWith('https:') /* useHttps */, ); } } else { - if (agentOverride !== false) { + if (httpAgent !== false) { const isHttps = url.startsWith('https:'); - if (isHttps && !(agentOverride instanceof HttpsAgent)) { + if (isHttps && !(httpAgent instanceof HttpsAgent)) { throw new Error( 'The endpoint `' + url + '` can only be paired with an `https.Agent`. You have, instead, supplied an ' + - '`http.Agent` through `agentOverride`.', + '`http.Agent` through `httpAgent`.', ); - } else if (!isHttps && agentOverride instanceof HttpsAgent) { + } else if (!isHttps && httpAgent instanceof HttpsAgent) { throw new Error( 'The endpoint `' + url + '` can only be paired with an `http.Agent`. You have, instead, supplied an ' + - '`https.Agent` through `agentOverride`.', + '`https.Agent` through `httpAgent`.', ); } - agentManager = {requestEnd() {}, requestStart: () => agentOverride}; + agentManager = {requestEnd() {}, requestStart: () => httpAgent}; } } } @@ -2898,7 +2898,7 @@ export type ConnectionConfig = { * persistence). Set this to `false` to create a connection that uses no agent. This applies to * Node environments only. */ - agentOverride?: HttpAgent | HttpsAgent | false; + httpAgent?: HttpAgent | HttpsAgent | false; /** Optional commitment level */ commitment?: Commitment; /** Optional endpoint URL to the fullnode JSON RPC PubSub WebSocket Endpoint */ @@ -3016,7 +3016,7 @@ export class Connection { let fetch; let fetchMiddleware; let disableRetryOnRateLimit; - let agentOverride; + let httpAgent; if (commitmentOrConfig && typeof commitmentOrConfig === 'string') { this._commitment = commitmentOrConfig; } else if (commitmentOrConfig) { @@ -3028,7 +3028,7 @@ export class Connection { fetch = commitmentOrConfig.fetch; fetchMiddleware = commitmentOrConfig.fetchMiddleware; disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit; - agentOverride = commitmentOrConfig.agentOverride; + httpAgent = commitmentOrConfig.httpAgent; } this._rpcEndpoint = assertEndpointUrl(endpoint); @@ -3040,7 +3040,7 @@ export class Connection { fetch, fetchMiddleware, disableRetryOnRateLimit, - agentOverride, + httpAgent, ); this._rpcRequest = createRpcRequest(this._rpcClient); this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient); diff --git a/web3.js/test/connection.test.ts b/web3.js/test/connection.test.ts index 2e18dac8dceeee..7e159eb09a6969 100644 --- a/web3.js/test/connection.test.ts +++ b/web3.js/test/connection.test.ts @@ -202,7 +202,7 @@ describe('Connection', function () { it('uses no agent with fetch when `overrideAgent` is `false`', () => { const fetch = spy(); - const c = new Connection(url, {agentOverride: false, fetch}); + const c = new Connection(url, {httpAgent: false, fetch}); c.getBlock(0); expect(fetch).to.have.been.calledWith( match.any, @@ -212,24 +212,24 @@ describe('Connection', function () { it('uses the supplied `overrideAgent` with fetch', () => { const fetch = spy(); - const agentOverride = new HttpsAgent(); - const c = new Connection('https://example.com', {agentOverride, fetch}); + const httpAgent = new HttpsAgent(); + const c = new Connection('https://example.com', {httpAgent, fetch}); c.getBlock(0); expect(fetch).to.have.been.calledWith( match.any, - match({agent: agentOverride}), + match({agent: httpAgent}), ); }); it('throws when the supplied `overrideAgent` is http but the endpoint is https', () => { expect(() => { - new Connection('https://example.com', {agentOverride: new HttpAgent()}); + new Connection('https://example.com', {httpAgent: new HttpAgent()}); }).to.throw; }); it('throws when the supplied `overrideAgent` is https but the endpoint is http', () => { expect(() => { - new Connection('http://example.com', {agentOverride: new HttpsAgent()}); + new Connection('http://example.com', {httpAgent: new HttpsAgent()}); }).to.throw; }); });