std.http.Server: responses to HEAD not allowed to have a payload

This commit is contained in:
Nameless
2023-08-23 15:29:50 -05:00
parent 3817c7382b
commit ddef683fcb
2 changed files with 6 additions and 4 deletions

View File

@@ -458,6 +458,10 @@ pub const Response = struct {
try w.print("{}", .{res.headers});
}
if (res.request.method == .HEAD) {
res.transfer_encoding = .none;
}
try w.writeAll("\r\n");
try buffered.flush();
@@ -520,10 +524,6 @@ pub const Response = struct {
res.request.parser.done = true;
}
if (res.request.method == .HEAD) {
res.request.parser.done = true;
}
if (!res.request.parser.done) {
if (res.request.transfer_compression) |tc| switch (tc) {
.compress => return error.CompressionNotSupported,

View File

@@ -55,6 +55,8 @@ fn handleRequest(res: *Server.Response) !void {
try res.writeAll("Hello, ");
try res.writeAll("World!\n");
try res.finish();
} else {
try testing.expectEqual(res.writeAll("errors"), error.NotWriteable);
}
} else if (mem.startsWith(u8, res.request.target, "/large")) {
res.transfer_encoding = .{ .content_length = 14 * 1024 + 14 * 10 };