somratpro commited on
Commit
db82b83
·
1 Parent(s): 5131b7d

fix: patch global undici dispatcher

Browse files
Files changed (1) hide show
  1. cloudflare-proxy.js +9 -1
cloudflare-proxy.js CHANGED
@@ -256,6 +256,14 @@ if (PROXY_URL) {
256
  patchDispatch(exports.Agent?.prototype, "Agent");
257
  patchDispatch(exports.ProxyAgent?.prototype, "ProxyAgent");
258
 
 
 
 
 
 
 
 
 
259
  if (exports.fetch && !exports.fetch._patched) {
260
  exports.fetch = async function (input, init) {
261
  return globalThis.fetch(input, init);
@@ -290,7 +298,7 @@ if (PROXY_URL) {
290
 
291
  // Patch already loaded undici instances
292
  for (const key in require.cache) {
293
- if (key.includes('/undici/')) {
294
  try { patchUndiciInstance(require.cache[key].exports); } catch (e) {}
295
  }
296
  }
 
256
  patchDispatch(exports.Agent?.prototype, "Agent");
257
  patchDispatch(exports.ProxyAgent?.prototype, "ProxyAgent");
258
 
259
+ // Patch the current global dispatcher
260
+ if (exports.getGlobalDispatcher) {
261
+ const globalDispatcher = exports.getGlobalDispatcher();
262
+ if (globalDispatcher && globalDispatcher.dispatch && !globalDispatcher.dispatch._patched) {
263
+ patchDispatch(globalDispatcher, "GlobalDispatcherInstance");
264
+ }
265
+ }
266
+
267
  if (exports.fetch && !exports.fetch._patched) {
268
  exports.fetch = async function (input, init) {
269
  return globalThis.fetch(input, init);
 
298
 
299
  // Patch already loaded undici instances
300
  for (const key in require.cache) {
301
+ if (key.includes('/undici/') || key.endsWith('/undici/index.js')) {
302
  try { patchUndiciInstance(require.cache[key].exports); } catch (e) {}
303
  }
304
  }