Skip to content

Commit 3e9faac

Browse files
committed
Make all fetch requests half-duplex to avoid errors in certain Node envs
1 parent fe7f397 commit 3e9faac

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/private/UploadManagerFetchUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class UploadManagerFetchUtils {
2626
headers,
2727
body: content,
2828
signal,
29+
duplex: "half",
2930
cache: "no-store" // Required for Next.js's Fetch implementation, which caches POST/PUT requests by default.
3031
});
3132

src/public/shared/generated/runtime.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ export class BaseAPI {
135135
//
136136
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
137137
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
138-
cache: "no-store"
138+
cache: "no-store",
139+
140+
// Node does not support full duplex, so default fetch implementations will fail with "RequestInit: duplex option is required when sending a body"
141+
// unless the following is set.
142+
// https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
143+
duplex: "half"
139144
});
140145
} catch (e) {
141146
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
@@ -313,7 +318,7 @@ export class BytescaleApiError extends Error {
313318
}
314319
}
315320

316-
export type FetchAPI = WindowOrWorkerGlobalScope["fetch"];
321+
export type FetchAPI = (input: RequestInfo | URL, init?: RequestInit & { duplex: "half" }) => Promise<Response>;
317322

318323
export type Json = any;
319324
export type HTTPMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD";

0 commit comments

Comments
 (0)