authorgravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-08-23 15:29:50-05:00
committergravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-08-29 21:42:54-05:00
logddef683fcb321882cc912090a25c12bc8705ff55
treed06228cf7b54f4610d498fe7a7d6c6fda97b0b65
parent3817c7382b66bbac0c8f7ea4ff45685bb41b6a63
signaturelock-open Commit is signed but in an unrecognized format.

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


2 files changed, 6 insertions(+), 4 deletions(-)

lib/std/http/Server.zig+4-4
...@@ -458,6 +458,10 @@ pub const Response = struct {...@@ -458,6 +458,10 @@ pub const Response = struct {
458 try w.print("{}", .{res.headers});458 try w.print("{}", .{res.headers});
459 }459 }
460460
461 if (res.request.method == .HEAD) {
462 res.transfer_encoding = .none;
463 }
464
461 try w.writeAll("\r\n");465 try w.writeAll("\r\n");
462466
463 try buffered.flush();467 try buffered.flush();
...@@ -520,10 +524,6 @@ pub const Response = struct {...@@ -520,10 +524,6 @@ pub const Response = struct {
520 res.request.parser.done = true;524 res.request.parser.done = true;
521 }525 }
522526
523 if (res.request.method == .HEAD) {
524 res.request.parser.done = true;
525 }
526
527 if (!res.request.parser.done) {527 if (!res.request.parser.done) {
528 if (res.request.transfer_compression) |tc| switch (tc) {528 if (res.request.transfer_compression) |tc| switch (tc) {
529 .compress => return error.CompressionNotSupported,529 .compress => return error.CompressionNotSupported,
test/standalone/http.zig+2
...@@ -55,6 +55,8 @@ fn handleRequest(res: *Server.Response) !void {...@@ -55,6 +55,8 @@ fn handleRequest(res: *Server.Response) !void {
55 try res.writeAll("Hello, ");55 try res.writeAll("Hello, ");
56 try res.writeAll("World!\n");56 try res.writeAll("World!\n");
57 try res.finish();57 try res.finish();
58 } else {
59 try testing.expectEqual(res.writeAll("errors"), error.NotWriteable);
58 }60 }
59 } else if (mem.startsWith(u8, res.request.target, "/large")) {61 } else if (mem.startsWith(u8, res.request.target, "/large")) {
60 res.transfer_encoding = .{ .content_length = 14 * 1024 + 14 * 10 };62 res.transfer_encoding = .{ .content_length = 14 * 1024 + 14 * 10 };