Skip to content

Change default "user-agent" from undici #2306

@balazsorban44

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

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