Skip to content

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

Closed as not planned

Description

@loynoir

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)

Activity

  1. hjain5164 commented on Apr 18, 2023

    @hjain5164

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

  2. bnoordhuis commented on Apr 18, 2023

    @bnoordhuis
    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.

  3. loynoir commented on Apr 18, 2023

    @loynoir
    Author

    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.

  4. ottob commented on Jul 31, 2023

    @ottob

    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

  5. bnoordhuis commented on Aug 1, 2023

    @bnoordhuis
    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.

  6. ottob commented on Aug 1, 2023

    @ottob

    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.

  7. bnoordhuis commented on Aug 1, 2023

    @bnoordhuis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.fetchIssues and PRs related to the Fetch API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions