mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
More elaborate fetcher API's
This commit is contained in:
@@ -9,9 +9,28 @@ const headerMap: Record<string, string> = {
|
||||
origin: 'X-Origin',
|
||||
};
|
||||
|
||||
const responseHeaderMap: Record<string, string> = {
|
||||
'x-set-cookie': 'Set-Cookie',
|
||||
};
|
||||
|
||||
export function makeSimpleProxyFetcher(proxyUrl: string, f: FetchLike): Fetcher {
|
||||
const fetcher = makeStandardFetcher(f);
|
||||
const proxiedFetch: Fetcher = async (url, ops) => {
|
||||
const fetcher = makeStandardFetcher(async (a, b) => {
|
||||
const res = await f(a, b);
|
||||
|
||||
// set extra headers that cant normally be accessed
|
||||
res.extraHeaders = new Headers();
|
||||
Object.entries(responseHeaderMap).forEach((entry) => {
|
||||
const value = res.headers.get(entry[0]);
|
||||
if (!value) return;
|
||||
res.extraHeaders?.set(entry[0].toLowerCase(), value);
|
||||
});
|
||||
|
||||
// set correct final url
|
||||
res.extraUrl = res.headers.get('X-Final-Destination') ?? res.url;
|
||||
return res;
|
||||
});
|
||||
|
||||
const fullUrl = makeFullUrl(url, ops);
|
||||
|
||||
const headerEntries = Object.entries(ops.headers).map((entry) => {
|
||||
|
Reference in New Issue
Block a user