-
Notifications
You must be signed in to change notification settings - Fork 575
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
Passing a custom agent to fetch()
#1489
Comments
This was already added in #1411. Support for Node.js https.Agent is not planned due to API incompatibilities. |
I understand, but: how can I do this in bare Node (with |
In order to do this you would need to:
At some future time this will be bundled in core. |
If anyone else is looking for a way to pass You need to install import { Agent } from 'undici';
await fetch('https://example.com', {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false,
},
}),
}); |
@bancek Using Doing |
After read the source code and the test case code , i find the solution. The
Also check the test case Proxy via HTTP to HTTPS endpoint and the proxy-agent source code. |
This would solve...
In some otherwise trivial cases for
fetch()
a custom, one-purpose agent is required to manage a request, e.g. in order to check a server's identity manually or to disregard that verification completely (self-signed certificates come to mind). Current approach, from what I've seen, requires passing a set of TLS options to a dispatcher explicitly, then using said dispatcher to invoke a request - maybe it's just me, but I feel this could be simplified.The implementation should look like...
Using
https.Agent
as an example:I have also considered...
Some parameters can be set via alternative means; environment variables come to mind:
However, I don't think applying this to every request is a good idea (same goes for any global agents).
Additional context
Implementations in similar projects:
axios
node-fetch
Possibly relevant issues:
The text was updated successfully, but these errors were encountered: