Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): reuse http agent across client #1216

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done inline now, I think it makes more sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's just to be sure both agent are in sync, don't you think it's less error prone like that?

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