From 49fd5b582d4c37343905e2957def481f43324507 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 28 Aug 2015 09:49:16 +0200 Subject: [PATCH] Fix: HttpHandler is calling HttpResponse::Finish twice for 404s fixes #10024 --- lib/remote/httphandler.cpp | 1 - lib/remote/httpresponse.cpp | 6 ++++++ lib/remote/httpresponse.hpp | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/remote/httphandler.cpp b/lib/remote/httphandler.cpp index 5b93e2cae..0e580fde3 100644 --- a/lib/remote/httphandler.cpp +++ b/lib/remote/httphandler.cpp @@ -104,7 +104,6 @@ void HttpHandler::ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request, response.AddHeader("Content-Type", "text/html"); String msg = "

Not found

"; response.WriteBody(msg.CStr(), msg.GetLength()); - response.Finish(); return; } } diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index d42fc68a8..649bcb8bd 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -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())); diff --git a/lib/remote/httpresponse.hpp b/lib/remote/httpresponse.hpp index 1bb8b13c1..6255ac134 100644 --- a/lib/remote/httpresponse.hpp +++ b/lib/remote/httpresponse.hpp @@ -31,7 +31,8 @@ enum HttpResponseState { HttpResponseStart, HttpResponseHeaders, - HttpResponseBody + HttpResponseBody, + HttpResponseEnd }; /** -- 2.40.0