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

companion commit to 919a3bae1c5f2024b09e127a15c752d9dc0aa9a6
This commit is contained in:
Andrew Kelley 2024-02-11 17:38:28 -07:00
parent 90bd4f226e
commit b47bd031ca

View File

@ -693,9 +693,11 @@ pub const Response = struct {
switch (res.transfer_encoding) {
.chunked => {
try res.connection.writer().print("{x}\r\n", .{bytes.len});
try res.connection.writeAll(bytes);
try res.connection.writeAll("\r\n");
if (bytes.len > 0) {
try res.connection.writer().print("{x}\r\n", .{bytes.len});
try res.connection.writeAll(bytes);
try res.connection.writeAll("\r\n");
}
return bytes.len;
},