From c10d8c833fc3585a898507620e407641f6473a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 10 Apr 2026 17:49:41 -0400 Subject: [PATCH] test: try undici 8 --- install/package.json | 2 +- src/request.js | 38 ++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/install/package.json b/install/package.json index 2ee7a2e127..c0df511828 100644 --- a/install/package.json +++ b/install/package.json @@ -151,7 +151,7 @@ "tinycon": "0.6.8", "toobusy-js": "0.5.1", "tough-cookie": "6.0.1", - "undici": "^7.10.0", + "undici": "8.0.2", "validator": "13.15.35", "webpack": "5.106.1", "webpack-merge": "6.0.1", diff --git a/src/request.js b/src/request.js index 3ffde3916e..307bac847c 100644 --- a/src/request.js +++ b/src/request.js @@ -1,8 +1,8 @@ 'use strict'; const dns = require('dns').promises; -require('undici'); // keep this here, needed for SSRF (see `lookup()`) - +// require('undici'); // keep this here, needed for SSRF (see `lookup()`) +const { Agent } = require('undici'); const nconf = require('nconf'); const ipaddr = require('ipaddr.js'); const { CookieJar } = require('tough-cookie'); @@ -72,7 +72,16 @@ function lookup(hostname, options, callback) { }); } -// Initialize fetch - somewhat hacky, but it's required for globalDispatcher to be available +const dispatcher = new Agent({ + connect: { lookup }, + interceptors: { + request: (opts) => { + delete opts.headers['sec-fetch-mode']; + return opts; + }, + }, +}); + async function call(url, method, { body, timeout, jar, ...config } = {}) { const { ok } = await check(url); if (!ok) { @@ -92,6 +101,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { 'user-agent': userAgent, ...config.headers, }, + dispatcher, }; if (timeout > 0) { opts.signal = AbortSignal.timeout(timeout); @@ -105,17 +115,17 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { } } // Workaround for https://github.com/nodejs/undici/issues/1305 - if (global[Symbol.for('undici.globalDispatcher.1')] !== undefined) { - class FetchAgent extends global[Symbol.for('undici.globalDispatcher.1')].constructor { - dispatch(opts, handler) { - delete opts.headers['sec-fetch-mode']; - return super.dispatch(opts, handler); - } - } - opts.dispatcher = new FetchAgent({ - connect: { lookup }, - }); - } + // if (global[Symbol.for('undici.globalDispatcher.1')] !== undefined) { + // class FetchAgent extends global[Symbol.for('undici.globalDispatcher.1')].constructor { + // dispatch(opts, handler) { + // delete opts.headers['sec-fetch-mode']; + // return super.dispatch(opts, handler); + // } + // } + // opts.dispatcher = new FetchAgent({ + // connect: { lookup }, + // }); + // } const response = await fetchImpl(url, opts);