fetchWorker: support RequestInit

This commit is contained in:
Alex Gleason
2023-11-28 20:55:43 -06:00
parent 5a954a304d
commit da3efaa5bc
5 changed files with 79 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
import { Comlink } from '@/deps.ts';
import './handlers/abortsignal.ts';
import type { FetchWorker } from './fetch.worker.ts';
const _worker = Comlink.wrap<typeof FetchWorker>(
@@ -9,10 +11,10 @@ const _worker = Comlink.wrap<typeof FetchWorker>(
),
);
const fetchWorker: typeof fetch = async (input) => {
const fetchWorker: typeof fetch = async (input, init) => {
const { signal, ...rest } = init || {};
const url = input instanceof Request ? input.url : input.toString();
const args = await _worker.fetch(url);
const args = await _worker.fetch(url, rest, signal);
return new Response(...args);
};