自定义调度程序
【Custom dispatcher】
你可以使用自定义调度器来分发请求,将其传递到 fetch 的选项对象中。调度器必须与 undici 的 Dispatcher 类 兼容。
【You can use a custom dispatcher to dispatch requests passing it in fetch's options object.
The dispatcher must be compatible with undici's
Dispatcher class.】
fetch(url, { dispatcher: new MyAgent() }); 可以通过安装 undici 并使用 setGlobalDispatcher() 方法来更改 Node.js 中的全局调度器。调用此方法将影响 undici 和 Node.js。
【It is possible to change the global dispatcher in Node.js by installing undici and using
the setGlobalDispatcher() method. Calling this method will affect both undici and
Node.js.】
import { setGlobalDispatcher } from 'undici';
setGlobalDispatcher(new MyAgent());