Merge branch 'main' into misc-improvements

This commit is contained in:
Killer069
2021-10-29 15:05:40 +05:30
committed by GitHub
7 changed files with 939 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ export type ProxyOptions = ProxyOpts | string;
interface RequestOpts extends RequestOptions {
body?: string;
method?: 'GET' | 'POST';
method?: 'GET' | 'POST' | 'HEAD';
proxies?: ProxyOptions[];
cookies?: boolean;
}
@@ -119,6 +119,23 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
});
}
export function request_resolve_redirect(url: string): Promise<string> {
return new Promise(async (resolve, reject) => {
let res = await https_getter(url, { method: 'HEAD' }).catch((err: Error) => err);
if (res instanceof Error) {
reject(res);
return;
}
const statusCode = Number(res.statusCode);
if (statusCode >= 300 && statusCode < 400) {
const resolved = await request_resolve_redirect(res.headers.location as string);
resolve(resolved);
} else {
resolve(url);
}
});
}
/**
* Chooses one random number between max and min number.
* @param min Minimum number