webapi: improve fetch/response correctness with null bodies

Responses with specific status (e.g. 204) should always have a null body. Also
adds validation to Response constructor (e.g. can't provide an invalid status).

Improves a handful of WPT tests:

fetch/api/response/response-error.any.html
fetch/api/response/response-static-json.any.html
This commit is contained in:
Karl Seguin committed 2026-09-19 13:38:12 +08:00
1 parent ae928a91b1
commit d28d37be92
5 files changed
+96 -5

No files matched your search

+5
View File
@@ -866,6 +866,11 @@ fn testHTTPHandler(req: *std.http.Server.Request) !void {
});
}
if (std.mem.startsWith(u8, path, "/status/")) {
const code = try std.fmt.parseInt(u16, path["/status/".len..], 10);
return req.respond("", .{ .status = @enumFromInt(code) });
}
if (std.mem.eql(u8, path, "/xhr/500")) {
return req.respond("Internal Server Error", .{
.status = .internal_server_error,