(
url: RequestInfo,
init: RequestInit | undefined,
ms: number,
controller: AbortController,
)
| 990 | } |
| 991 | |
| 992 | async fetchWithTimeout( |
| 993 | url: RequestInfo, |
| 994 | init: RequestInit | undefined, |
| 995 | ms: number, |
| 996 | controller: AbortController, |
| 997 | ): Promise<Response> { |
| 998 | const { signal, method, ...options } = init || {}; |
| 999 | const abort = this._makeAbort(controller); |
| 1000 | if (signal) signal.addEventListener('abort', abort, { once: true }); |
| 1001 | |
| 1002 | const timeout = setTimeout(abort, ms); |
| 1003 | |
| 1004 | const isReadableBody = |
| 1005 | ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) || |
| 1006 | (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body); |
| 1007 | |
| 1008 | const fetchOptions: RequestInit = { |
| 1009 | signal: controller.signal as any, |
| 1010 | ...(isReadableBody ? { duplex: 'half' } : {}), |
| 1011 | method: 'GET', |
| 1012 | ...options, |
| 1013 | }; |
| 1014 | if (method) { |
| 1015 | // Custom methods like 'patch' need to be uppercased |
| 1016 | // See https://github.com/nodejs/undici/issues/2294 |
| 1017 | fetchOptions.method = method.toUpperCase(); |
| 1018 | } |
| 1019 | |
| 1020 | try { |
| 1021 | // use undefined this binding; fetch errors if bound to something else in browser/cloudflare |
| 1022 | return await this.fetch.call(undefined, url, fetchOptions); |
| 1023 | } finally { |
| 1024 | clearTimeout(timeout); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | private async shouldRetry(response: Response): Promise<boolean> { |
| 1029 | // Note this is not a standard header. |
no test coverage detected