Skip to content

Commit b790294

Browse files
committed
fix: allow passing timeout value to sendRequest
1 parent 4743034 commit b790294

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/resolvers/url.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import type { FileInfo } from "../types/index.js";
66
export const sendRequest = async ({
77
init,
88
redirects = [],
9+
timeout = 60_000,
910
url,
1011
}: {
1112
init?: RequestInit;
1213
redirects?: string[];
14+
timeout?: number;
1315
url: URL | string;
1416
}): Promise<{
1517
response: Response;
@@ -21,14 +23,19 @@ export const sendRequest = async ({
2123
const controller = new AbortController();
2224
const timeoutId = setTimeout(() => {
2325
controller.abort();
24-
}, 60_000);
26+
}, timeout);
2527
const response = await fetch(url, {
2628
signal: controller.signal,
2729
...init,
2830
});
2931
clearTimeout(timeoutId);
3032

3133
if (response.status >= 400) {
34+
// gracefully handle HEAD method not allowed
35+
if (response.status === 405 && init?.method === 'HEAD') {
36+
return { response };
37+
}
38+
3239
throw ono({ status: response.status }, `HTTP ERROR ${response.status}`);
3340
}
3441

@@ -49,6 +56,7 @@ export const sendRequest = async ({
4956
return sendRequest({
5057
init,
5158
redirects,
59+
timeout,
5260
url: resolve(url.href, response.headers.location as string),
5361
});
5462
}

0 commit comments

Comments
 (0)