diff --git a/lib/internal/modules/esm/fetch_module.js b/lib/internal/modules/esm/fetch_module.js index 7638f94b3fe525..182dfd2a0f6657 100644 --- a/lib/internal/modules/esm/fetch_module.js +++ b/lib/internal/modules/esm/fetch_module.js @@ -53,6 +53,10 @@ function HTTPSGet(url, opts) { return https.get(url, { agent: HTTPSAgent, ...opts, + headers: { + 'user-agent': `Node.js/${process.version}`, + ...opts?.headers, + }, }); } @@ -65,6 +69,10 @@ function HTTPGet(url, opts) { return http.get(url, { agent: HTTPAgent, ...opts, + headers: { + 'user-agent': `Node.js/${process.version}`, + ...opts?.headers, + }, }); } diff --git a/test/es-module/test-http-imports.mjs b/test/es-module/test-http-imports.mjs index 235d142d3555e3..15ef089df338c7 100644 --- a/test/es-module/test-http-imports.mjs +++ b/test/es-module/test-http-imports.mjs @@ -67,6 +67,8 @@ for (const { protocol, createServer } of [ // ?body sets the body, string const server = createServer(function(_req, res) { const url = new URL(_req.url, host); + assert.strictEqual(_req.headers['user-agent'], `Node.js/${process.version}`); + const redirect = url.searchParams.get('redirect'); if (url.pathname === '/not-found') { res.writeHead(404);