From 6bafd2d706a88ba1c90533161304768aee96d541 Mon Sep 17 00:00:00 2001 From: mferrera Date: Sat, 22 Nov 2025 19:04:43 +0100 Subject: [PATCH] std.http: allow fetching with no payload When a POST, PUT, or PATCH request is sent by Client.fetch without a payload an assert fails in `sendBodiless` as these methods are expected to have a body. However, the HTTP spec does not _require_ them to have a body. --- lib/std/http/Client.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 431f239db30b..b0a565dec3a9 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -1803,6 +1803,11 @@ pub fn fetch(client: *Client, options: FetchOptions) FetchError!FetchResult { try body.writer.writeAll(payload); try body.end(); try req.connection.?.flush(); + } else if (http.Method.requestHasBody(req.method)) { + req.transfer_encoding = .{ .content_length = 0 }; + var body = try req.sendBodyUnflushed(&.{}); + try body.end(); + try req.connection.?.flush(); } else { try req.sendBodiless(); }