Skip to content

Commit f6e9e56

Browse files
author
Samuel Bodin
authored
fix(node): reuse http agent across client (#1216)
1 parent 5207d68 commit f6e9e56

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/requester-node-http/src/createNodeHttpRequester.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ export type NodeHttpRequesterOptions = {
1212
httpsAgent?: https.Agent;
1313
};
1414

15+
const agentOptions = { keepAlive: true };
16+
const defaultHttpAgent = new http.Agent(agentOptions);
17+
const defaultHttpsAgent = new https.Agent(agentOptions);
18+
1519
export function createNodeHttpRequester({
1620
agent: userGlobalAgent,
1721
httpAgent: userHttpAgent,
1822
httpsAgent: userHttpsAgent,
1923
}: NodeHttpRequesterOptions = {}): Requester & Destroyable {
20-
const agentOptions = { keepAlive: true };
21-
const httpAgent = userHttpAgent || userGlobalAgent || new http.Agent(agentOptions);
22-
const httpsAgent = userHttpsAgent || userGlobalAgent || new https.Agent(agentOptions);
24+
const httpAgent = userHttpAgent || userGlobalAgent || defaultHttpAgent;
25+
const httpsAgent = userHttpsAgent || userGlobalAgent || defaultHttpsAgent;
2326

2427
return {
2528
send(request: Request): Readonly<Promise<Response>> {

0 commit comments

Comments
 (0)