From 13239c3172b625f615b663cd809530b1441149dc Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 9 Oct 2018 13:23:23 +0200 Subject: [PATCH] Ensure that HTTP/1.0 or Connection: close headers are properly disconnecting the client Test results: https://github.com/Icinga/icinga2/issues/6514#issuecomment-428155731 fixes #6514 --- lib/remote/httpresponse.cpp | 3 --- lib/remote/httpserverconnection.cpp | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 45ac25c81..cfe99d608 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -111,9 +111,6 @@ void HttpResponse::Finish() } m_State = HttpResponseEnd; - - if (m_Request->ProtocolVersion == HttpVersion10 || m_Request->Headers->Get("connection") == "close") - m_Stream->Shutdown(); } bool HttpResponse::Parse(StreamReadContext& src, bool may_wait) diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index 497ce7b83..aa960c25b 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -357,6 +357,13 @@ void HttpServerConnection::DataAvailableHandler() } m_RequestQueue.Enqueue(std::bind(&Stream::SetCorked, m_Stream, false)); + + /* Request finished, decide whether to explicitly close the connection. */ + if (m_CurrentRequest.ProtocolVersion == HttpVersion10 || + m_CurrentRequest.Headers->Get("connection") == "close") { + m_Stream->Shutdown(); + close = true; + } } else close = true; -- 2.40.0