mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
http: protect against zero-length chunks
A zero-length chunk marks the end of the body, so prevent any from possibly occurring in the middle of the body.
This commit is contained in:
parent
3122fd0ba0
commit
919a3bae1c
1 changed files with 5 additions and 3 deletions
|
|
@ -1018,9 +1018,11 @@ pub const Request = struct {
|
|||
pub fn write(req: *Request, bytes: []const u8) WriteError!usize {
|
||||
switch (req.transfer_encoding) {
|
||||
.chunked => {
|
||||
try req.connection.?.writer().print("{x}\r\n", .{bytes.len});
|
||||
try req.connection.?.writer().writeAll(bytes);
|
||||
try req.connection.?.writer().writeAll("\r\n");
|
||||
if (bytes.len > 0) {
|
||||
try req.connection.?.writer().print("{x}\r\n", .{bytes.len});
|
||||
try req.connection.?.writer().writeAll(bytes);
|
||||
try req.connection.?.writer().writeAll("\r\n");
|
||||
}
|
||||
|
||||
return bytes.len;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue