From b0a9c5673e7a8a100ddd827b780abe7d284802c1 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 30 Sep 2021 12:19:54 +0330 Subject: 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. --- Userland/Libraries/LibHTTP/HttpJob.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries/LibHTTP/HttpJob.cpp') diff --git a/Userland/Libraries/LibHTTP/HttpJob.cpp b/Userland/Libraries/LibHTTP/HttpJob.cpp index 58ab0e28d6..6e0115c341 100644 --- a/Userland/Libraries/LibHTTP/HttpJob.cpp +++ b/Userland/Libraries/LibHTTP/HttpJob.cpp @@ -43,13 +43,17 @@ void HttpJob::start(NonnullRefPtr socket) }; } -void HttpJob::shutdown() +void HttpJob::shutdown(ShutdownMode mode) { if (!m_socket) return; - m_socket->on_ready_to_read = nullptr; - m_socket->on_connected = nullptr; - m_socket = nullptr; + if (mode == ShutdownMode::CloseSocket) { + m_socket->close(); + } else { + m_socket->on_ready_to_read = nullptr; + m_socket->on_connected = nullptr; + m_socket = nullptr; + } } void HttpJob::register_on_ready_to_read(Function callback) -- cgit v1.2.3