diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-30 12:19:54 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-30 11:46:37 +0200 |
commit | b0a9c5673e7a8a100ddd827b780abe7d284802c1 (patch) | |
tree | 282c91f61d3f2f11f8661a193a27a8e4a7fc5ad8 /Userland/Libraries/LibHTTP/Job.cpp | |
parent | d16131b100aaf74e2d69207aea2c8a586bec6f1e (diff) | |
download | serenity-b0a9c5673e7a8a100ddd827b780abe7d284802c1.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibHTTP/Job.cpp')
-rw-r--r-- | Userland/Libraries/LibHTTP/Job.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 97c4b317bd..8141a3e869 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -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); }); } |