feat: update deno-fetch-auto-proxy-mod.ts
This commit is contained in:
@@ -16,3 +16,23 @@ export function getFetchAutoProxyInit(): RequestInit | undefined {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchWithTimoutAndAutoProxy(
|
||||||
|
input: URL | Request | string,
|
||||||
|
timeout?: number,
|
||||||
|
initCallback?: (init: RequestInit) => RequestInit,
|
||||||
|
): Promise<Response> {
|
||||||
|
const fetchTimeout = timeout || 10000;
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const timoutHandler = setTimeout(() => {
|
||||||
|
abortController.abort(`Timout ${fetchTimeout} ms`);
|
||||||
|
}, fetchTimeout);
|
||||||
|
let init = getFetchAutoProxyInit() || {};
|
||||||
|
init.signal = abortController.signal;
|
||||||
|
if (initCallback) {
|
||||||
|
init = initCallback(init);
|
||||||
|
}
|
||||||
|
const response = await fetch(input, init);
|
||||||
|
clearTimeout(timoutHandler);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user