authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-19 17:08:49+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-20 10:42:21+00:00
logb05fefb9c9bf3065e353102d0e54ea76d5f4e34d
tree8648f141532ac235245af263eb4577506f79dda2
parentbc524a2b1a6e5cd13c0093bed240b06d23e1a882
signaturelock-open Commit is signed but in an unrecognized format.

std.http: stop assuming previous chunk state

The full file may not be written, either due to a previous chunk being in-progress when `sendFile` was called, or due to `limit`.

1 files changed, 3 insertions(+), 4 deletions(-)

lib/std/http.zig+3-4
...@@ -962,6 +962,7 @@ pub const BodyWriter = struct {...@@ -962,6 +962,7 @@ pub const BodyWriter = struct {
962 // have to flush the chunk header before knowing the chunk length.962 // have to flush the chunk header before knowing the chunk length.
963 return error.Unimplemented;963 return error.Unimplemented;
964 };964 };
965 if (data_len == 0) return error.EndOfStream;
965 const out = bw.http_protocol_output;966 const out = bw.http_protocol_output;
966 l: switch (bw.state.chunk_len) {967 l: switch (bw.state.chunk_len) {
967 0 => {968 0 => {
...@@ -975,8 +976,7 @@ pub const BodyWriter = struct {...@@ -975,8 +976,7 @@ pub const BodyWriter = struct {
975 2 => {976 2 => {
976 try out.writeAll("\r\n");977 try out.writeAll("\r\n");
977 bw.state.chunk_len = 0;978 bw.state.chunk_len = 0;
978 assert(file_reader.atEnd());979 continue :l 0;
979 return error.EndOfStream;
980 },980 },
981 else => {981 else => {
982 const chunk_limit: std.Io.Limit = .limited(bw.state.chunk_len - 2);982 const chunk_limit: std.Io.Limit = .limited(bw.state.chunk_len - 2);
...@@ -985,8 +985,7 @@ pub const BodyWriter = struct {...@@ -985,8 +985,7 @@ pub const BodyWriter = struct {
985 else985 else
986 try out.write(chunk_limit.slice(w.buffered()));986 try out.write(chunk_limit.slice(w.buffered()));
987 bw.state.chunk_len -= n;987 bw.state.chunk_len -= n;
988 const ret = w.consume(n);988 return w.consume(n);
989 return ret;
990 },989 },
991 }990 }
992 }991 }