KITFORMA · EDITORIAL ANSWER
Why does a Node HTTPS Agent not configure built-in fetch connections?
KitForma editorial guide. Built-in Node fetch uses Undici rather than the node:https Agent interface. An agent option copied from another HTTP client does not configure its connection dispatcher.
Step-by-step answer
fetch(url, { dispatcher }). Keep an application-owned dispatcher reusable instead of constructing a connection manager for every request. If using setGlobalDispatcher, remember that it changes both built-in fetch and the installed Undici client; a library should not silently replace application-wide transport policy. Check process.versions.undici and the installed package compatibility before adopting version-specific options. Test that the intended dispatcher receives a controlled request, then separately verify proxy, TLS and pool behavior against an owned endpoint. Never disable certificate verification to make an incompatible agent appear to work.
Minimal example:
import assert from 'node:assert/strict';
const marker = new Error('controlled dispatcher failure');
let invoked = false;
const dispatcher = { dispatch() { invoked = true; throw marker; } };
await assert.rejects(
fetch('https://example.invalid/', { dispatcher }),
error => error.cause === marker
);
assert.equal(invoked, true);
// Tests dispatcher wiring only; no socket, proxy or TLS connection is opened.Sources and verification
Sources checked:
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.