From 9ec246a2f42cd356408a11cd9ed6f0d90fd1ca33 Mon Sep 17 00:00:00 2001
From: Michael Friedrich <michael.friedrich@icinga.com>
Date: Thu, 12 Sep 2019 17:00:17 +0200
Subject: [PATCH] Revert: Always reset Boost beast buffer in
 HttpServerConnection#ProcessMessages #7476

Not a simple revert but also adds a comment for the buffer.

refs #7476
---
 lib/remote/httpserverconnection.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp
index 2589c9d7d..cdbcc7c57 100644
--- a/lib/remote/httpserverconnection.cpp
+++ b/lib/remote/httpserverconnection.cpp
@@ -495,6 +495,11 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
 	namespace http = beast::http;
 
 	try {
+		/* Do not reset the buffer in the state machine.
+		 * EnsureValidHeaders already reads from the stream into the buffer,
+		 * EnsureValidBody continues. ProcessRequest() actually handles the request
+		 * and needs the full buffer.
+		 */
 		beast::flat_buffer buf;
 
 		for (;;) {
@@ -508,8 +513,6 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
 
 			response.set(http::field::server, l_ServerHeader);
 
-			// Best practice is to always reset the buffer.
-			buf = {};
 			if (!EnsureValidHeaders(*m_Stream, buf, parser, response, m_ShuttingDown, yc)) {
 				break;
 			}
@@ -555,8 +558,6 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
 				break;
 			}
 
-			// Best practice is to always reset the buffer.
-			buf = {};
 			if (!EnsureValidBody(*m_Stream, buf, parser, authenticatedUser, response, m_ShuttingDown, yc)) {
 				break;
 			}