authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-05-02 22:19:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:28-07:00
log847afd0a47021934801a9d44ba39a8a241de5458
tree1b71d69448735323eb0b9296ad0b9499fe401826
parente4126aa213e30d4fe93981a27160acc56e3db4f8

std.http: fix chunked header offset calculation


1 files changed, 6 insertions(+), 5 deletions(-)

lib/std/http.zig+6-5
......@@ -809,8 +809,9 @@ pub const BodyWriter = struct {
809809 end,
810810
811811 pub const Chunked = union(enum) {
812 /// Index of the hex-encoded chunk length in the chunk header
813 /// within the buffer of `BodyWriter.http_protocol_output`.
812 /// Index to the start of the hex-encoded chunk length in the chunk
813 /// header within the buffer of `BodyWriter.http_protocol_output`.
814 /// Buffered chunk data starts here plus length of `chunk_header_template`.
814815 offset: usize,
815816 /// We are in the middle of a chunk and this is how many bytes are
816817 /// left until the next header. This includes +2 for "\r"\n", and
......@@ -830,7 +831,7 @@ pub const BodyWriter = struct {
830831 .end, .none, .content_length => return w.http_protocol_output.flush(),
831832 .chunked => |*chunked| switch (chunked.*) {
832833 .offset => |*offset| {
833 try w.http_protocol_output.flushLimit(.limited(w.http_protocol_output.end - offset.*));
834 try w.http_protocol_output.flushLimit(.limited(offset.*));
834835 offset.* = 0;
835836 },
836837 .chunk_len => return w.http_protocol_output.flush(),
......@@ -1025,8 +1026,8 @@ pub const BodyWriter = struct {
10251026 },
10261027 .chunk_len => |chunk_len| l: switch (chunk_len) {
10271028 0 => {
1028 const header_buf = try bw.writableArray(chunk_header_template.len);
10291029 const off = bw.end;
1030 const header_buf = try bw.writableArray(chunk_header_template.len);
10301031 @memcpy(header_buf, chunk_header_template);
10311032 chunked.* = .{ .offset = off };
10321033 continue :state .{ .offset = off };
......@@ -1074,8 +1075,8 @@ pub const BodyWriter = struct {
10741075 },
10751076 .chunk_len => |chunk_len| l: switch (chunk_len) {
10761077 0 => {
1077 const header_buf = try bw.writableArray(chunk_header_template.len);
10781078 const offset = bw.end;
1079 const header_buf = try bw.writableArray(chunk_header_template.len);
10791080 @memcpy(header_buf, chunk_header_template);
10801081 chunked.* = .{ .offset = offset };
10811082 continue :state .{ .offset = offset };