Skip to content

Commit

Permalink
fix(node): reuse http agent across client (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Bodin authored Oct 19, 2020
1 parent 5207d68 commit f6e9e56
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/requester-node-http/src/createNodeHttpRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ export type NodeHttpRequesterOptions = {
httpsAgent?: https.Agent;
};

const agentOptions = { keepAlive: true };
const defaultHttpAgent = new http.Agent(agentOptions);
const defaultHttpsAgent = new https.Agent(agentOptions);

export function createNodeHttpRequester({
agent: userGlobalAgent,
httpAgent: userHttpAgent,
httpsAgent: userHttpsAgent,
}: NodeHttpRequesterOptions = {}): Requester & Destroyable {
const agentOptions = { keepAlive: true };
const httpAgent = userHttpAgent || userGlobalAgent || new http.Agent(agentOptions);
const httpsAgent = userHttpsAgent || userGlobalAgent || new https.Agent(agentOptions);
const httpAgent = userHttpAgent || userGlobalAgent || defaultHttpAgent;
const httpsAgent = userHttpsAgent || userGlobalAgent || defaultHttpsAgent;

return {
send(request: Request): Readonly<Promise<Response>> {
Expand Down

0 comments on commit f6e9e56

Please sign in to comment.