forked from FoundKeyGang/FoundKey
server: fix default arguments for fetch
This commit is contained in:
parent
75ab4de41f
commit
b61e477c0c
1 changed files with 18 additions and 3 deletions
|
@ -33,11 +33,26 @@ export async function getHtml(url: string, accept = 'text/html, */*', timeout =
|
||||||
return await res.text();
|
return await res.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getResponse(args: { url: string, method: string, body?: string, headers: Record<string, string>, timeout: number = 10 * SECOND, size?: number, redirect: 'follow' | 'manual' | 'error' = 'follow' }) {
|
export async function getResponse(_args: {
|
||||||
|
url: string,
|
||||||
|
method: string,
|
||||||
|
body?: string,
|
||||||
|
headers: Record<string, string>,
|
||||||
|
timeout?: number,
|
||||||
|
size?: number,
|
||||||
|
redirect?: 'follow' | 'manual' | 'error',
|
||||||
|
}) {
|
||||||
|
const args = {
|
||||||
|
timeout: 10 * SECOND,
|
||||||
|
size: 10 * 1024 * 1024, // 10 MiB
|
||||||
|
redirect: 'follow',
|
||||||
|
..._args,
|
||||||
|
};
|
||||||
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
controller.abort();
|
controller.abort();
|
||||||
}, timeout);
|
}, args.timeout);
|
||||||
|
|
||||||
const res = await fetch(args.url, {
|
const res = await fetch(args.url, {
|
||||||
method: args.method,
|
method: args.method,
|
||||||
|
@ -46,7 +61,7 @@ export async function getResponse(args: { url: string, method: string, body?: st
|
||||||
}, args.headers),
|
}, args.headers),
|
||||||
body: args.body,
|
body: args.body,
|
||||||
redirect: args.redirect,
|
redirect: args.redirect,
|
||||||
size: args.size || 10 * 1024 * 1024, // 10 MiB
|
size: args.size,
|
||||||
agent: getAgentByUrl,
|
agent: getAgentByUrl,
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue