create std.http.Server.Response.deinit to handle keepalive connections

This commit is contained in:
Ryo Ota 2023-04-21 10:17:16 +09:00
parent 06763c4c8c
commit afebef2465
2 changed files with 5 additions and 2 deletions

View File

@ -336,6 +336,10 @@ pub const Response = struct {
headers: http.Headers,
request: Request,
pub fn deinit(res: *Response) void {
res.server.allocator.destroy(res);
}
/// Reset this response to its initial state. This must be called before handling a second request on the same connection.
pub fn reset(res: *Response) void {
res.request.headers.deinit();
@ -359,8 +363,6 @@ pub const Response = struct {
if (res.request.parser.header_bytes_owned) {
res.request.parser.header_bytes.deinit(res.server.allocator);
}
res.server.allocator.destroy(res);
} else {
res.request.parser.reset();
}

View File

@ -30,6 +30,7 @@ test "client requests server" {
const server_thread = try std.Thread.spawn(.{}, (struct {
fn apply(s: *std.http.Server) !void {
const res = try s.accept(.{ .dynamic = max_header_size });
defer res.deinit();
defer res.reset();
try res.wait();