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
|
||||
};
|
||||
|
||||
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 body = await response.arrayBuffer();
|
||||
|
||||
|
@ -50,6 +50,7 @@ export type ConnectionInfo = {
|
||||
throttleCallback?: (attempt: number, url: string) => Promise<boolean>,
|
||||
|
||||
skipFetchSetup?: boolean;
|
||||
fetchOptions?: Record<string, string>;
|
||||
errorPassThrough?: boolean;
|
||||
|
||||
timeout?: number,
|
||||
@ -158,7 +159,12 @@ export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo,
|
||||
if (connection.skipFetchSetup != null) {
|
||||
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 dataMatch = ((url) ? url.match(reData): null);
|
||||
if (dataMatch) {
|
||||
|
@ -13,5 +13,6 @@ export type Options = {
|
||||
body?: Uint8Array;
|
||||
headers?: { [ key: string] : string };
|
||||
skipFetchSetup?: boolean;
|
||||
fetchOptions?: Record<string, string>;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user