test: try undici 8

This commit is contained in:
Barış Soner Uşaklı
2026-04-10 17:49:41 -04:00
parent 6f4ce68445
commit c10d8c833f
2 changed files with 25 additions and 15 deletions

View File

@@ -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",

View File

@@ -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);