Skip to content

Commit

Permalink
fix: Request constructor override
Browse files Browse the repository at this point in the history
Use ReadableStream.from instead of Readable.toWeb
The latter triggers a "This ReadableStream is disturbed" error
See cloudflare/workerd#3245
  • Loading branch information
vicb committed Dec 15, 2024
1 parent 429e880 commit 02e0d0e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ fetch = globalThis.fetch;
const CustomRequest = class extends globalThis.Request {
constructor(input, init) {
if (init) {
delete init.cache;
if (init.body?.__node_stream__ === true) {
init = {
...init,
cache: undefined,
// https://github.com/cloudflare/workerd/issues/2746
init.body = __cf_stream.Readable.toWeb(init.body);
}
// https://github.com/cloudflare/workerd/issues/3245
body: init.body instanceof __cf_stream.Readable ? ReadableStream.from(init.body) : init.body,
};
}
super(input, init);
}
Expand Down

0 comments on commit 02e0d0e

Please sign in to comment.