Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nimirium authored Dec 12, 2024
2 parents 7c4282a + f51f759 commit 82bd90d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/transport/node-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,16 @@ export class NodeTransport implements Transport {
* @internal
*/
private agentForTransportRequest(req: TransportRequest): HttpAgent | HttpsAgent | undefined {
// Don't configure any agents if keep alive not requested.
if (!this.keepAlive && !this.proxyConfiguration) return undefined;

// Create proxy agent (if possible).
if (this.proxyConfiguration)
return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new ProxyAgent(this.proxyConfiguration));

// Create keep alive agent.
const useSecureAgent = req.origin!.startsWith('https:');

if (useSecureAgent && this.httpsAgent === undefined)
this.httpsAgent = new HttpsAgent({ keepAlive: true, ...this.keepAliveSettings });
else if (!useSecureAgent && this.httpAgent === undefined) {
this.httpAgent = new HttpAgent({ keepAlive: true, ...this.keepAliveSettings });
}
const agentOptions = { keepAlive: this.keepAlive, ...(this.keepAlive ? this.keepAliveSettings : {}) };
if (useSecureAgent && this.httpsAgent === undefined) this.httpsAgent = new HttpsAgent(agentOptions);
else if (!useSecureAgent && this.httpAgent === undefined) this.httpAgent = new HttpAgent(agentOptions);

return useSecureAgent ? this.httpsAgent : this.httpAgent;
}
Expand Down

0 comments on commit 82bd90d

Please sign in to comment.