Commit 17af53554e

Ryo Ota <nwtgck@nwtgck.org>
2023-04-17 12:33:25
HTTP client and server send "0\r\n\r\n" when chunked encoding
1 parent 1fb0b5a
Changed files (2)
lib/std/http/Client.zig
@@ -856,7 +856,7 @@ pub const Request = struct {
     /// Finish the body of a request. This notifies the server that you have no more data to send.
     pub fn finish(req: *Request) !void {
         switch (req.headers.transfer_encoding) {
-            .chunked => req.connection.data.conn.writeAll("0\r\n") catch |err| {
+            .chunked => req.connection.data.conn.writeAll("0\r\n\r\n") catch |err| {
                 req.client.last_error = .{ .write = err };
                 return error.WriteFailed;
             },
lib/std/http/Server.zig
@@ -517,7 +517,7 @@ pub const Response = struct {
     /// Finish the body of a request. This notifies the server that you have no more data to send.
     pub fn finish(res: *Response) !void {
         switch (res.headers.transfer_encoding) {
-            .chunked => try res.connection.writeAll("0\r\n"),
+            .chunked => try res.connection.writeAll("0\r\n\r\n"),
             .content_length => |len| if (len != 0) return error.MessageNotCompleted,
             .none => {},
         }