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 = {
|
||||
text(): Promise<string>;
|
||||
json(): Promise<any>;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
extraHeaders?: FetchHeaders;
|
||||
extraUrl?: string;
|
||||
headers: FetchHeaders;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue