mirror of
https://github.com/p-stream/providers.git
synced 2026-01-11 20:10:33 +00:00
update proxy to support wasm responses
This commit is contained in:
parent
f8c0aa098c
commit
eebb285972
2 changed files with 18 additions and 3 deletions
|
|
@ -19,6 +19,7 @@ export type FetchHeaders = {
|
||||||
export type FetchReply = {
|
export type FetchReply = {
|
||||||
text(): Promise<string>;
|
text(): Promise<string>;
|
||||||
json(): Promise<any>;
|
json(): Promise<any>;
|
||||||
|
arrayBuffer(): Promise<ArrayBuffer>;
|
||||||
extraHeaders?: FetchHeaders;
|
extraHeaders?: FetchHeaders;
|
||||||
extraUrl?: string;
|
extraUrl?: string;
|
||||||
headers: FetchHeaders;
|
headers: FetchHeaders;
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,23 @@ export function makeStandardFetcher(f: FetchLike): Fetcher {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
let body: any;
|
let body: any;
|
||||||
const isJson = res.headers.get('content-type')?.includes('application/json');
|
const contentType = res.headers.get('content-type')?.toLowerCase();
|
||||||
if (isJson) body = await res.json();
|
const isJson = contentType?.includes('application/json');
|
||||||
else body = await res.text();
|
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 {
|
return {
|
||||||
body,
|
body,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue