From 1ff7122b99c1b0c7c807c69b2eca8a1aab5ed1e0 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 11 Oct 2023 11:40:07 -0400 Subject: [PATCH] fix user-agent detection --- lib/fetch/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 8c98a646a0e..d18db8e9b0b 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1344,7 +1344,9 @@ async function httpNetworkOrCacheFetch ( // user agents should append `User-Agent`/default `User-Agent` value to // httpRequest’s header list. if (!httpRequest.headersList.contains('user-agent')) { - httpRequest.headersList.append('user-agent', __filename.endsWith('index.js') ? 'undici' : 'node') + // __commonJS is injected by esbuild when bundled. The esbuild bundle is used in node core. + // Therefore if we're running the esbuild bundle, we're likely in node core. + httpRequest.headersList.append('user-agent', typeof __commonJS !== 'function' ? 'undici' : 'node') } // 15. If httpRequest’s cache mode is "default" and httpRequest’s header