Skip to content

Commit 53d84b3

Browse files
committed
fix: set proper User-Agent header on outgoing HTTP requests
Yarn currently sends 'got (https://github.com/sindresorhus/got)' as the User-Agent header, making it impossible to distinguish Yarn traffic. Set it to follow the convention used by npm and pnpm: yarn/<version> node/<node_version> Fixes #7146
1 parent 6861e75 commit 53d84b3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/yarnpkg-core/sources/httpUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {ReportError} from './Report';
1212
import * as formatUtils from './formatUtils';
1313
import {MapValue, MapValueToObjectValue} from './miscUtils';
1414
import * as miscUtils from './miscUtils';
15+
import {YarnVersion} from './YarnVersion';
1516

1617
export type {RequestError} from 'got';
1718

@@ -238,7 +239,8 @@ async function requestImpl(target: string | URL, body: Body, {configuration, hea
238239
if (url.protocol === `http:` && !micromatch.isMatch(url.hostname, configuration.get(`unsafeHttpWhitelist`)))
239240
throw new ReportError(MessageName.NETWORK_UNSAFE_HTTP, `Unsafe http requests must be explicitly whitelisted in your configuration (${url.hostname})`);
240241

241-
const gotOptions: ExtendOptions = {headers, method};
242+
const userAgent = `yarn/${YarnVersion ?? 'unknown'} node/${process.versions.node}`;
243+
const gotOptions: ExtendOptions = {headers: {['user-agent']: userAgent, ...headers}, method};
242244
gotOptions.responseType = jsonResponse
243245
? `json`
244246
: `buffer`;

0 commit comments

Comments
 (0)