1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

LibHTTP: Respect the 'Connection: close' header on keep-alive jobs

If the server responds with this header, we _must_ close the connection,
as the server is allowed to ignore the socket and not respond to
anything past that response.
Fixes some RequestServer spins.
This commit is contained in:
Ali Mohammad Pur 2021-09-30 12:19:54 +03:30 committed by Andreas Kling
parent d16131b100
commit b0a9c5673e
13 changed files with 55 additions and 23 deletions

View file

@ -412,6 +412,10 @@ void Job::finish_up()
m_has_scheduled_finish = true;
auto response = HttpResponse::create(m_code, move(m_headers));
deferred_invoke([this, response = move(response)] {
// If the server responded with "Connection: close", close the connection
// as the server may or may not want to close the socket.
if (auto result = response->headers().get("Connection"sv); result.has_value() && result.value().equals_ignoring_case("close"sv))
shutdown(ShutdownMode::CloseSocket);
did_finish(response);
});
}