authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-11 17:38:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-23 02:37:10-07:00
logb47bd031ca0b8c3a14c0dd6537e13e60779471a4
tree30f0f73c8016ae7af6d9a83839ba696bd388bf2e
parent90bd4f226e2ba03634d31c73df06bf0a90fa0231

std.http.Server: protect against zero-length chunks

companion commit to 919a3bae1c5f2024b09e127a15c752d9dc0aa9a6

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

lib/std/http/Server.zig+5-3
...@@ -693,9 +693,11 @@ pub const Response = struct {...@@ -693,9 +693,11 @@ pub const Response = struct {
693693
694 switch (res.transfer_encoding) {694 switch (res.transfer_encoding) {
695 .chunked => {695 .chunked => {
696 try res.connection.writer().print("{x}\r\n", .{bytes.len});696 if (bytes.len > 0) {
697 try res.connection.writeAll(bytes);697 try res.connection.writer().print("{x}\r\n", .{bytes.len});
698 try res.connection.writeAll("\r\n");698 try res.connection.writeAll(bytes);
699 try res.connection.writeAll("\r\n");
700 }
699701
700 return bytes.len;702 return bytes.len;
701 },703 },