From 0e173da86fe93fd0c87257e8f68cc6fedc4c59e7 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 18 Feb 2022 14:17:51 +0330 Subject: WebServer: Close the socket if Connection: keep-alive isn't requested --- Userland/Services/WebServer/Client.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Userland/Services') diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index cfdfe6aab7..95dc899560 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -203,6 +203,14 @@ ErrorOr Client::send_response(InputStream& response, HTTP::HttpRequest con } } while (true); + auto keep_alive = false; + if (auto it = request.headers().find_if([](auto& header) { return header.name.equals_ignoring_case("Connection"); }); !it.is_end()) { + if (it->value.trim_whitespace().equals_ignoring_case("keep-alive")) + keep_alive = true; + } + if (!keep_alive) + m_socket->close(); + return {}; } -- cgit v1.2.3