| ... | @@ -809,8 +809,9 @@ pub const BodyWriter = struct { | ... | @@ -809,8 +809,9 @@ pub const BodyWriter = struct { |
| 809 | end, | 809 | end, |
| 810 | | 810 | |
| 811 | pub const Chunked = union(enum) { | 811 | pub const Chunked = union(enum) { |
| 812 | /// Index of the hex-encoded chunk length in the chunk header | 812 | /// Index to the start of the hex-encoded chunk length in the chunk |
| 813 | /// within the buffer of `BodyWriter.http_protocol_output`. | 813 | /// header within the buffer of `BodyWriter.http_protocol_output`. |
| | 814 | /// Buffered chunk data starts here plus length of `chunk_header_template`. |
| 814 | offset: usize, | 815 | offset: usize, |
| 815 | /// We are in the middle of a chunk and this is how many bytes are | 816 | /// We are in the middle of a chunk and this is how many bytes are |
| 816 | /// left until the next header. This includes +2 for "\r"\n", and | 817 | /// left until the next header. This includes +2 for "\r"\n", and |
| ... | @@ -830,7 +831,7 @@ pub const BodyWriter = struct { | ... | @@ -830,7 +831,7 @@ pub const BodyWriter = struct { |
| 830 | .end, .none, .content_length => return w.http_protocol_output.flush(), | 831 | .end, .none, .content_length => return w.http_protocol_output.flush(), |
| 831 | .chunked => |*chunked| switch (chunked.*) { | 832 | .chunked => |*chunked| switch (chunked.*) { |
| 832 | .offset => |*offset| { | 833 | .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.*)); |
| 834 | offset.* = 0; | 835 | offset.* = 0; |
| 835 | }, | 836 | }, |
| 836 | .chunk_len => return w.http_protocol_output.flush(), | 837 | .chunk_len => return w.http_protocol_output.flush(), |
| ... | @@ -1025,8 +1026,8 @@ pub const BodyWriter = struct { | ... | @@ -1025,8 +1026,8 @@ pub const BodyWriter = struct { |
| 1025 | }, | 1026 | }, |
| 1026 | .chunk_len => |chunk_len| l: switch (chunk_len) { | 1027 | .chunk_len => |chunk_len| l: switch (chunk_len) { |
| 1027 | 0 => { | 1028 | 0 => { |
| 1028 | const header_buf = try bw.writableArray(chunk_header_template.len); | | |
| 1029 | const off = bw.end; | 1029 | const off = bw.end; |
| | 1030 | const header_buf = try bw.writableArray(chunk_header_template.len); |
| 1030 | @memcpy(header_buf, chunk_header_template); | 1031 | @memcpy(header_buf, chunk_header_template); |
| 1031 | chunked.* = .{ .offset = off }; | 1032 | chunked.* = .{ .offset = off }; |
| 1032 | continue :state .{ .offset = off }; | 1033 | continue :state .{ .offset = off }; |
| ... | @@ -1074,8 +1075,8 @@ pub const BodyWriter = struct { | ... | @@ -1074,8 +1075,8 @@ pub const BodyWriter = struct { |
| 1074 | }, | 1075 | }, |
| 1075 | .chunk_len => |chunk_len| l: switch (chunk_len) { | 1076 | .chunk_len => |chunk_len| l: switch (chunk_len) { |
| 1076 | 0 => { | 1077 | 0 => { |
| 1077 | const header_buf = try bw.writableArray(chunk_header_template.len); | | |
| 1078 | const offset = bw.end; | 1078 | const offset = bw.end; |
| | 1079 | const header_buf = try bw.writableArray(chunk_header_template.len); |
| 1079 | @memcpy(header_buf, chunk_header_template); | 1080 | @memcpy(header_buf, chunk_header_template); |
| 1080 | chunked.* = .{ .offset = offset }; | 1081 | chunked.* = .{ .offset = offset }; |
| 1081 | continue :state .{ .offset = offset }; | 1082 | continue :state .{ .offset = offset }; |