mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
28 lines
663 B
TypeScript
28 lines
663 B
TypeScript
import { Comlink, Debug } from '@/deps.ts';
|
|
|
|
import './handlers/abortsignal.ts';
|
|
|
|
const debug = Debug('ditto:fetch.worker');
|
|
|
|
export const FetchWorker = {
|
|
async fetch(
|
|
url: string,
|
|
init: Omit<RequestInit, 'signal'>,
|
|
signal: AbortSignal | null | undefined,
|
|
): Promise<[BodyInit, ResponseInit]> {
|
|
debug(init.method, url);
|
|
const response = await fetch(url, { ...init, signal });
|
|
return [
|
|
await response.arrayBuffer(),
|
|
{
|
|
status: response.status,
|
|
statusText: response.statusText,
|
|
headers: [...response.headers.entries()],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
Comlink.expose(FetchWorker);
|
|
|
|
self.postMessage('ready');
|