From afebef2465a828132f87cd2aeff0c5873ca10de5 Mon Sep 17 00:00:00 2001 From: Ryo Ota Date: Fri, 21 Apr 2023 10:17:16 +0900 Subject: [PATCH] create std.http.Server.Response.deinit to handle keepalive connections --- lib/std/http/Server.zig | 6 ++++-- lib/std/http/test.zig | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig index b1205594ad..59b76ea20d 100644 --- a/lib/std/http/Server.zig +++ b/lib/std/http/Server.zig @@ -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(); } diff --git a/lib/std/http/test.zig b/lib/std/http/test.zig index 7c053dc6b3..ce55c21392 100644 --- a/lib/std/http/test.zig +++ b/lib/std/http/test.zig @@ -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();