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.
This commit is contained in:
mferrera 2025-11-22 19:04:43 +01:00
parent 3f2cf1c002
commit 6bafd2d706

View file

@ -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();
}