zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ddef683fcb321882cc912090a25c12bc8705ff55 (tree)
parent 3817c7382b66bbac0c8f7ea4ff45685bb41b6a63
Author: Nameless <truemedian@gmail.com>
Date:   Wed, 23 Aug 2023 15:29:50 -0500

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

Diffstat:
Mlib/std/http/Server.zig | 8++++----
Mtest/standalone/http.zig | 2++
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig @@ -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, diff --git a/test/standalone/http.zig b/test/standalone/http.zig @@ -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 };