aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-09-01 20:10:54 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-01 20:10:54 -0700
commit0019073c8a19a9fff166fb42ec5f32d7f6fb3ee1 (patch)
treed8fa2c7973a4010839126421b321ca84194a5fe7 /src/bun.js
parent45edb7bcf780a492c418ddd551210c2613b5a562 (diff)
downloadbun-0019073c8a19a9fff166fb42ec5f32d7f6fb3ee1.tar.gz
bun-0019073c8a19a9fff166fb42ec5f32d7f6fb3ee1.tar.zst
bun-0019073c8a19a9fff166fb42ec5f32d7f6fb3ee1.zip
fix `Bun.serve` with tls and `Bun.file` (#4450)
* check sendfile ctx * add test * undo blob check * undo undo and add assert
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/server.zig24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index acb0b1a10..5bbf159d2 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -2021,17 +2021,25 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
const is_temporary = result.result.is_temporary;
+
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(this.blob == .Blob);
+ }
+
if (!is_temporary) {
this.blob.Blob.resolveSize();
this.doRenderBlob();
} else {
const stat_size = @as(Blob.SizeType, @intCast(result.result.total_size));
- const original_size = this.blob.Blob.size;
- this.blob.Blob.size = if (original_size == 0 or original_size == Blob.max_size)
- stat_size
- else
- @min(original_size, stat_size);
+ if (this.blob == .Blob) {
+ const original_size = this.blob.Blob.size;
+
+ this.blob.Blob.size = if (original_size == 0 or original_size == Blob.max_size)
+ stat_size
+ else
+ @min(original_size, stat_size);
+ }
if (!this.flags.has_written_status)
this.flags.needs_content_range = true;
@@ -2040,7 +2048,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
this.sendfile = .{
.fd = bun.invalid_fd,
.remain = @as(Blob.SizeType, @truncate(result.result.buf.len)),
- .offset = this.blob.Blob.offset,
+ .offset = if (this.blob == .Blob) this.blob.Blob.offset else 0,
.auto_close = false,
.socket_fd = -999,
};
@@ -5585,7 +5593,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
return;
}
- if (!ctx.flags.has_marked_complete and !ctx.flags.has_marked_pending and ctx.pending_promises_for_abort == 0 and !ctx.flags.is_waiting_for_request_body) {
+ if (!ctx.flags.has_marked_complete and !ctx.flags.has_marked_pending and ctx.pending_promises_for_abort == 0 and !ctx.flags.is_waiting_for_request_body and !ctx.flags.has_sendfile_ctx) {
ctx.renderMissing();
return;
}
@@ -5655,7 +5663,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
return;
}
- if (!ctx.flags.has_marked_complete and !ctx.flags.has_marked_pending and ctx.pending_promises_for_abort == 0 and !ctx.flags.is_waiting_for_request_body) {
+ if (!ctx.flags.has_marked_complete and !ctx.flags.has_marked_pending and ctx.pending_promises_for_abort == 0 and !ctx.flags.is_waiting_for_request_body and !ctx.flags.has_sendfile_ctx) {
ctx.renderMissing();
return;
}