Line data Source code
1 1 : export async function nativeProxyFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
2 1 : const request = new Request(input, init);
3 1 : const bridge = globalThis.dashqlElectron;
4 1 : if (bridge === undefined) return await fetch(request);
5 :
6 1 : const headers: Array<[string, string]> = [];
7 1 : request.headers.forEach((value, name) => headers.push([name, value]));
8 1 : const response = await bridge.nativeProxyRequest({
9 1 : body: new Uint8Array(await request.arrayBuffer()),
10 1 : headers,
11 1 : method: request.method,
12 1 : url: request.url,
13 1 : }) as {body: Uint8Array; headers: Array<[string, string]>; status: number; statusText: string};
14 1 : return new Response(new Uint8Array(response.body), {
15 1 : headers: response.headers,
16 1 : status: response.status,
17 1 : statusText: response.statusText,
18 1 : });
19 1 : }
|