Allow browser fetch option overrides (#3096).
This commit is contained in:
parent
d9046dd5f5
commit
c309df8a3e
@ -23,6 +23,15 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes
|
|||||||
request.referrer = "client"; // no-referrer, *client
|
request.referrer = "client"; // no-referrer, *client
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.fetchOptions != null) {
|
||||||
|
const opts = options.fetchOptions;
|
||||||
|
if (opts.mode) { request.mode = <RequestMode>(opts.mode); }
|
||||||
|
if (opts.cache) { request.cache = <RequestCache>(opts.cache); }
|
||||||
|
if (opts.credentials) { request.credentials = <RequestCredentials>(opts.credentials); }
|
||||||
|
if (opts.redirect) { request.redirect = <RequestRedirect>(opts.redirect); }
|
||||||
|
if (opts.referrer) { request.referrer = opts.referrer; }
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(href, request);
|
const response = await fetch(href, request);
|
||||||
const body = await response.arrayBuffer();
|
const body = await response.arrayBuffer();
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ export type ConnectionInfo = {
|
|||||||
throttleCallback?: (attempt: number, url: string) => Promise<boolean>,
|
throttleCallback?: (attempt: number, url: string) => Promise<boolean>,
|
||||||
|
|
||||||
skipFetchSetup?: boolean;
|
skipFetchSetup?: boolean;
|
||||||
|
fetchOptions?: Record<string, string>;
|
||||||
errorPassThrough?: boolean;
|
errorPassThrough?: boolean;
|
||||||
|
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
@ -158,7 +159,12 @@ export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo,
|
|||||||
if (connection.skipFetchSetup != null) {
|
if (connection.skipFetchSetup != null) {
|
||||||
options.skipFetchSetup = !!connection.skipFetchSetup;
|
options.skipFetchSetup = !!connection.skipFetchSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connection.fetchOptions != null) {
|
||||||
|
options.fetchOptions = shallowCopy(connection.fetchOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reData = new RegExp("^data:([a-z0-9-]+/[a-z0-9-]+);base64,(.*)$", "i");
|
const reData = new RegExp("^data:([a-z0-9-]+/[a-z0-9-]+);base64,(.*)$", "i");
|
||||||
const dataMatch = ((url) ? url.match(reData): null);
|
const dataMatch = ((url) ? url.match(reData): null);
|
||||||
if (dataMatch) {
|
if (dataMatch) {
|
||||||
|
@ -13,5 +13,6 @@ export type Options = {
|
|||||||
body?: Uint8Array;
|
body?: Uint8Array;
|
||||||
headers?: { [ key: string] : string };
|
headers?: { [ key: string] : string };
|
||||||
skipFetchSetup?: boolean;
|
skipFetchSetup?: boolean;
|
||||||
|
fetchOptions?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user