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

to have fetchOptions.lookup and fetchOptions.socketPath, node should expose undici.Agent #47592

Closed
loynoir opened this issue Apr 17, 2023 · 7 comments
Labels
feature request Issues that request new features to be added to Node.js. fetch Issues and PRs related to the Fetch API

Comments

@loynoir
Copy link

loynoir commented Apr 17, 2023

What is the problem this feature will solve?

builtin fetch missing fetchOptions.lookup and fetchOptions.socketPath

$ npm add undici
$ node
Welcome to Node.js v18.15.0.
Type ".help" for more information.
> {Agent}=require('undici')
...
> await fetch('http://localhost/version', {dispatcher:new Agent({connect:{lookup:console.log}})})
localhost ...
> await (await fetch('http://localhost/version', {dispatcher:new Agent({socketPath: '/var/run/docker.sock'})})).json()
{
  Platform: 

What is the feature you are proposing to solve the problem?

$ node
Welcome to Node.js v18.15.0.
Type ".help" for more information.
> {Agent}=require('node:undici')
...
> await fetch('http://localhost/version', {dispatcher:new Agent({connect:{lookup:console.log}})})
localhost ...
> await (await fetch('http://localhost/version', {dispatcher:new Agent({socketPath: '/var/run/docker.sock'})})).json()
{
  Platform: 

What alternatives have you considered?

{FETCH_AGENT} = require('node:some_symbols')
Agent = fetch[FETCH_AGENT]

Related

nodejs/undici#421 (comment)

@loynoir loynoir added the feature request Issues that request new features to be added to Node.js. label Apr 17, 2023
@VoltrexKeyva VoltrexKeyva added the fetch Issues and PRs related to the Fetch API label Apr 17, 2023
@hjain5164
Copy link

Hi @VoltrexKeyva, I would like to work on this issue. Can you give me some guidance to proceed on this?

@bnoordhuis
Copy link
Member

I don't think node should be exposing all kinds of non-standard extensions. If you need more configurability, either use undici or node-fetch directly, or switch to node's own http client.

@loynoir
Copy link
Author

loynoir commented Apr 18, 2023

dns and socket are server side fetch stuff.

I don't think node should be exposing all kinds of non-standard extensions.

If dns and socket is non-standard to fetch, there must be something wrong or imperfect.

@ottob
Copy link

ottob commented Jul 31, 2023

I needed this for configuring tls client certificates (mutual tls / mtls) using the new core fetch client.

I think this is a quite common task for back-end initiated https requests, so it would be nice not having to install additional libraries for this.

ref: #48977

@bnoordhuis
Copy link
Member

I'd say there's zero chance of this feature request getting implemented as-is but there's an open issue about exposing undici's global dispatcher: #43187

You can also pass in your own dispatcher to individual fetch() calls, as explained in e.g. #48977 (comment).

I'll go ahead and close this but keep an eye on the other issue.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2023
@ottob
Copy link

ottob commented Aug 1, 2023

You can also pass in your own dispatcher to individual fetch() calls, as explained in e.g. #48977 (comment).

Thanks for looking at this issue.

Sorry for the noob question, but how can this be done without also having to import undici to get access to the Agent as Alex did in that issue? The point was not having to import undici since it is already in core.

@bnoordhuis
Copy link
Member

At least for now you can't get around importing undici into your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. fetch Issues and PRs related to the Fetch API
Projects
None yet
Development

No branches or pull requests

5 participants