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

HTTP and HTTPS agent #588

Closed
normanrz opened this issue Mar 11, 2019 · 3 comments

Comments

@normanrz
Copy link

commented Mar 11, 2019

I am trying to use keep-alive agent with node-fetch as described in #423, but I have a problem with HTTPS redirects. Initially, I call a HTTP resource which returns a redirect to a HTTPS resource. In the default node-fetch this is not a problem, because the agent is set based on the current request. When overriding the agent there is no way of having per-request agents.

I would propose an API that allows a function instead of a fixed agent:

fetch(url, { agent: (protocol) => protocol === 'https' ? httpsAgent : httpAgent })
@bitinn

This comment has been minimized.

Copy link
Owner

commented Mar 16, 2019

Yes this is a known limit, but since agent is non-standard I doubt there will be much change to this.

However, if you are lucky enough to be using nodejs 11.7.0+, globalAgent is now replaceable, meaning you can control this precisely:

@normanrz

This comment has been minimized.

Copy link
Author

commented Mar 17, 2019

Thanks for pointing to that change in node 11.

@bitinn

This comment has been minimized.

Copy link
Owner

commented May 16, 2019

this issue is addressed in v2.6.0, options.agent now accepts a function, see readme:

https://github.com/bitinn/node-fetch#custom-agent

@bitinn bitinn closed this May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.