自定义调度程序
¥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 installing undici
and using
the setGlobalDispatcher()
method. Calling this method will affect both undici
and
Node.js.
import { setGlobalDispatcher } from 'undici';
setGlobalDispatcher(new MyAgent());