Commit b47bd031ca

Andrew Kelley <andrew@ziglang.org>
2024-02-12 01:38:28
std.http.Server: protect against zero-length chunks
companion commit to 919a3bae1c5f2024b09e127a15c752d9dc0aa9a6
1 parent 90bd4f2
Changed files (1)
lib
std
lib/std/http/Server.zig
@@ -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;
             },