Skip to content

feat(core): set default HTTP user agent#7149

Open
kgrg wants to merge 1 commit into
yarnpkg:masterfrom
kgrg:feat/user-agent-header
Open

feat(core): set default HTTP user agent#7149
kgrg wants to merge 1 commit into
yarnpkg:masterfrom
kgrg:feat/user-agent-header

Conversation

@kgrg

@kgrg kgrg commented May 23, 2026

Copy link
Copy Markdown

Bug description

Yarn HTTP requests currently fall back to got's default User-Agent, which identifies the HTTP client rather than Yarn itself. This makes it difficult for sysadmins to distinguish Yarn traffic or enforce package-manager/version allow-lists.

Closes #7146

Root cause

httpUtils.request forwarded caller-provided headers directly to got. When callers didn't provide a User-Agent, got supplied its own default header.

Fix

  • Add a default User-Agent header for Yarn HTTP requests in the form yarn/<version> node/<node-version>
  • Use the bundled Yarn version when available, falling back to the core package version for source/test environments
  • Preserve custom User-Agent headers when callers/plugins explicitly provide one
  • Cover the default and custom-header behavior in httpUtils unit tests

Verification

  • yarn test:unit packages/yarnpkg-core/tests/httpUtils.test.ts --runInBand
  • yarn typecheck:all
  • git diff --check

Note

I also tried yarn test:lint, but it failed before linting the changed files with an ESLint config-loader error: TypeError: Cannot convert undefined or null to object.

Risk

Low. The change only adds a default header when no User-Agent is already configured; explicit caller-provided values are left unchanged.

@kgrg kgrg force-pushed the feat/user-agent-header branch 2 times, most recently from 30d0544 to 50cdefc Compare May 23, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Set a proper User-Agent header on outgoing HTTP request

1 participant