update proxy to support wasm responses

This commit is contained in:
Pas 2025-11-03 16:27:23 -07:00
parent f8c0aa098c
commit eebb285972
2 changed files with 18 additions and 3 deletions

View file

@ -19,6 +19,7 @@ export type FetchHeaders = {
export type FetchReply = {
text(): Promise<string>;
json(): Promise<any>;
arrayBuffer(): Promise<ArrayBuffer>;
extraHeaders?: FetchHeaders;
extraUrl?: string;
headers: FetchHeaders;

View file

@ -41,9 +41,23 @@ export function makeStandardFetcher(f: FetchLike): Fetcher {
clearTimeout(timeoutId);
let body: any;
const isJson = res.headers.get('content-type')?.includes('application/json');
if (isJson) body = await res.json();
else body = await res.text();
const contentType = res.headers.get('content-type')?.toLowerCase();
const isJson = contentType?.includes('application/json');
const isBinary =
contentType?.includes('application/wasm') ||
contentType?.includes('application/octet-stream') ||
contentType?.includes('binary');
// Handle 204 No Content responses - they have no body
if (res.status === 204) {
body = null;
} else if (isJson) {
body = await res.json();
} else if (isBinary) {
body = await res.arrayBuffer();
} else {
body = await res.text();
}
return {
body,