From 6513eb4696551a91e322fe2d9879335cd73c92db Mon Sep 17 00:00:00 2001 From: Nameless Date: Thu, 27 Apr 2023 20:25:46 -0500 Subject: [PATCH] std.http.Server: use client recommendation for keepalive --- lib/std/http/Server.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig index 1b5fd045fa..71a7a351ad 100644 --- a/lib/std/http/Server.zig +++ b/lib/std/http/Server.zig @@ -439,7 +439,14 @@ pub const Response = struct { } if (!res.headers.contains("connection")) { - try w.writeAll("Connection: keep-alive\r\n"); + const req_connection = res.request.headers.getFirstValue("connection"); + const req_keepalive = req_connection != null and !std.ascii.eqlIgnoreCase("close", req_connection.?); + + if (req_keepalive) { + try w.writeAll("Connection: keep-alive\r\n"); + } else { + try w.writeAll("Connection: close\r\n"); + } } const has_transfer_encoding = res.headers.contains("transfer-encoding");