]> granicus.if.org Git - icinga2/commitdiff
Fix: HttpHandler is calling HttpResponse::Finish twice for 404s
authorGunnar Beutner <gunnar@beutner.name>
Fri, 28 Aug 2015 07:49:16 +0000 (09:49 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 28 Aug 2015 07:49:31 +0000 (09:49 +0200)
fixes #10024

lib/remote/httphandler.cpp
lib/remote/httpresponse.cpp
lib/remote/httpresponse.hpp

index 5b93e2cae0b3317bd57e5408ed7c071ed78e2978..0e580fde3b32a5584aa002cbf290c477b73e8715 100644 (file)
@@ -104,7 +104,6 @@ void HttpHandler::ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request,
                response.AddHeader("Content-Type", "text/html");
                String msg = "<h1>Not found</h1>";
                response.WriteBody(msg.CStr(), msg.GetLength());
-               response.Finish();
                return;
        }
 }
index d42fc68a8a6986e116d758021149ed40166c417f..649bcb8bd7b81b52ff22f0c7e6a1f9ee633430eb 100644 (file)
@@ -72,6 +72,9 @@ void HttpResponse::WriteBody(const char *data, size_t count)
 {
        ASSERT(m_State == HttpResponseHeaders || m_State == HttpResponseBody);
 
+       if (count == 0)
+               return;
+
        if (m_Request.ProtocolVersion == HttpVersion10) {
                if (!m_Body)
                        m_Body = new FIFO();
@@ -86,6 +89,9 @@ void HttpResponse::WriteBody(const char *data, size_t count)
 
 void HttpResponse::Finish(void)
 {
+       ASSERT(m_State != HttpResponseEnd);
+       m_State = HttpResponseEnd;
+
        if (m_Request.ProtocolVersion == HttpVersion10) {
                if (m_Body)
                        AddHeader("Content-Length", Convert::ToString(m_Body->GetAvailableBytes()));
index 1bb8b13c112494ca25bf6b7d4cc58ca6e1b49c69..6255ac134f448576494e4d0def693b24bd9e9c03 100644 (file)
@@ -31,7 +31,8 @@ enum HttpResponseState
 {
        HttpResponseStart,
        HttpResponseHeaders,
-       HttpResponseBody
+       HttpResponseBody,
+       HttpResponseEnd
 };
 
 /**