Fix: HttpHandler is calling HttpResponse::Finish twice for 404s

fixes #10024
This commit is contained in:
Gunnar Beutner 2015-08-28 09:49:16 +02:00
parent f1a1dfb26e
commit 49fd5b582d
3 changed files with 8 additions and 2 deletions

View 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;
}
}

View 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()));

View File

@ -31,7 +31,8 @@ enum HttpResponseState
{
HttpResponseStart,
HttpResponseHeaders,
HttpResponseBody
HttpResponseBody,
HttpResponseEnd
};
/**