Skip to content

Change default "user-agent" from undici #2306

Closed

Description

@balazsorban44

What is the problem this feature will solve?

Currently, Node.js uses undici for its fetch implementation. This sets undici as the default user agent.

From Node.js' perspective, undici is an implementation detail and so it should have its own user agent header.

For context at Next.js, we stopped polyfilling globalThis.fetch in favor of the platform-provided alternative (previously using node-fetch), and started getting reports where users did not know where the requests with the undici user agent were coming from.

I've tested the current behavior in different runtimes, here is Node.js, Bun and Deno for comparison:

  • Node.js node node.mjs prints: undici:
// node.mjs
import { createServer } from 'http'
const server = createServer((req, res) => {
  console.log(req.headers['user-agent'])
  res.end()
}).listen(3000)
await fetch('http://localhost:3000')
server.close()
process.exit(0)
  • Bun bun bun.js prints: Bun/1.0.2:
// bun.js
const server = Bun.serve({
  port: 3000,
  fetch: (req) => console.log(req.headers.get('user-agent')),
})
await fetch('http://localhost:3000')
server.stop()
  • Deno deno run --allow-net deno.js prints: Deno/1.37.1:
// deno.js
Deno.serve({ port: 3000 }, (request) => {
  console.log(request.headers.get('user-agent'))
  return new Response()
})
await fetch('http://localhost:3000')
Deno.exit(0)

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

I propose that the default user agent in Node.js changes to the format used by Deno, and Bun for consistency.

Example: Node/18.18.0

What alternatives have you considered?

Related: nodejs/node#43852 nodejs/node#43851

Activity

  1. Ethan-Arrowood commented on Oct 2, 2023

    @Ethan-Arrowood
    Collaborator

    I'm 👍 for this change. Undici should maybe be dynamic and still return undici when called directly from Undici, but then when in Node.js it uses Node/<Version>. Not sure how to implement that exactly off the top of my head though.

  2. mscdex commented on Oct 2, 2023

    @mscdex

    I'd rather have User-Agent be opt-in, but at the very least it should not contain version information.

  3. Ethan-Arrowood commented on Oct 2, 2023

    @Ethan-Arrowood
    Collaborator

    What would the opt-in mechanism be?

    I also agree -- for lower level http apis. Fetch is high-enough level that I believe its okay to be making default decisions like user-agent header.

  4. KhafraDev commented on Oct 2, 2023

    @KhafraDev
    Member

    If httpRequest’s header list does not contain User-Agent, then user agents should append (User-Agent, default User-Agent value) to httpRequest’s header list.

    spec-wise we have to add a user-agent header.

  5. balazsorban44 commented on Oct 2, 2023

    @balazsorban44
    ContributorAuthor

    we have to add

    I'd rather have User-Agent be opt-in

    Keep in mind, it's already there, its value is just confusing.

    What would be the argument for not adding a version number? Most clients I can think of has one. 🤔

  6. mscdex commented on Oct 2, 2023

    @mscdex

    What would be the argument for not adding a version number?

    At least for security reasons.

  7. KhafraDev commented on Oct 2, 2023

    @KhafraDev
    Member

    Keep in mind that browsers are actually removing info from the user agent headers, for the reason mentioned above. https://developer.chrome.com/blog/user-agent-reduction-android-model-and-version/

  8. changed the title [-]Change default "user-agent" to `Node/version`[/-] [+]Change default "user-agent" from `undici`[/+] on Oct 3, 2023
  9. benjamingr commented on Oct 3, 2023

    @benjamingr
    Member

    I'm +1 to changing it to simply "node" or something similar

  10. Ethan-Arrowood commented on Oct 3, 2023

    @Ethan-Arrowood
    Collaborator

    Based on the way browsers are going let's settle on switching it to "node" or "nodejs". Since that is significantly more recognizable than "undici"

  11. KhafraDev commented on Oct 3, 2023

    @KhafraDev
    Member

    I don't have an opinion, anything is fine with me

  12. transferred this issue fromnodejs/nodeon Oct 4, 2023
  13. mcollina commented on Oct 4, 2023

    @mcollina
    SponsorMember

    I would rather not have one, but the spec mandate us. node is better than undici because it's 3 bytes less.

    Who wants to do the honors?

  14. Ethan-Arrowood commented on Oct 4, 2023

    @Ethan-Arrowood
    Collaborator

    On it 🚀

  15. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 28, 2024
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions