mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
create std.http.Server.Response.deinit to handle keepalive connections
This commit is contained in:
parent
06763c4c8c
commit
afebef2465
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user