aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-09-05 19:22:09 -0300
committerGravatar GitHub <noreply@github.com> 2023-09-05 15:22:09 -0700
commit6e50dd210fb052a4db4867fa03fe450ce87b4179 (patch)
treee8b4c5d7db0ced46065bf08fe37602532a48ac9f /src
parentd268097ded4513abe3cff9ca0037f72e90c23a21 (diff)
downloadbun-6e50dd210fb052a4db4867fa03fe450ce87b4179.tar.gz
bun-6e50dd210fb052a4db4867fa03fe450ce87b4179.tar.zst
bun-6e50dd210fb052a4db4867fa03fe450ce87b4179.zip
fix(fetch) always use readable stream if it is available (#4503)
* always use readable stream if it is available * use bun sleep * fix tests * rm uws dep
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/webcore/response.zig57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index 8fc282cf0..da1655821 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -792,6 +792,36 @@ pub const Fetch = struct {
return;
}
+ if (this.readable_stream_ref.get()) |readable| {
+ if (readable.ptr == .Bytes) {
+ readable.ptr.Bytes.size_hint = this.getSizeHint();
+ // body can be marked as used but we still need to pipe the data
+ var scheduled_response_buffer = this.scheduled_response_buffer.list;
+
+ const chunk = scheduled_response_buffer.items;
+
+ if (this.result.has_more) {
+ readable.ptr.Bytes.onData(
+ .{
+ .temporary = bun.ByteList.initConst(chunk),
+ },
+ bun.default_allocator,
+ );
+
+ // clean for reuse later
+ this.scheduled_response_buffer.reset();
+ } else {
+ readable.ptr.Bytes.onData(
+ .{
+ .temporary_and_done = bun.ByteList.initConst(chunk),
+ },
+ bun.default_allocator,
+ );
+ }
+ return;
+ }
+ }
+
if (this.response.get()) |response_js| {
if (response_js.as(Response)) |response| {
const body = response.body;
@@ -854,33 +884,6 @@ pub const Fetch = struct {
old.resolve(&response.body.value, this.global_this);
}
}
- } else if (this.readable_stream_ref.get()) |readable| {
- if (readable.ptr == .Bytes) {
- readable.ptr.Bytes.size_hint = this.getSizeHint();
- // body can be marked as used but we still need to pipe the data
- var scheduled_response_buffer = this.scheduled_response_buffer.list;
-
- const chunk = scheduled_response_buffer.items;
-
- if (this.result.has_more) {
- readable.ptr.Bytes.onData(
- .{
- .temporary = bun.ByteList.initConst(chunk),
- },
- bun.default_allocator,
- );
-
- // clean for reuse later
- this.scheduled_response_buffer.reset();
- } else {
- readable.ptr.Bytes.onData(
- .{
- .temporary_and_done = bun.ByteList.initConst(chunk),
- },
- bun.default_allocator,
- );
- }
- }
}
}
}