From a148540720aa645306807d8a2eb2f901b88f153e Mon Sep 17 00:00:00 2001 From: Simon Lepasteur Date: Thu, 31 Mar 2016 16:36:20 +0200 Subject: [PATCH] Fix header reading on linux listener using HTTPS. The first asynchronous read of the stream was stopping at the first CRLF (after the HTTP version) instead of reading until CRLFCRLF (the end of the header). This bug was not always noticeable because, as stated in the boost documentation: "After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine." Therefore the bug appeared only when trying to read the body of the request and the streambuf filled by async_read_until did not contain the complete header. --- Release/src/http/listener/http_server_asio.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Release/src/http/listener/http_server_asio.cpp b/Release/src/http/listener/http_server_asio.cpp index 14f3383b8e..63ea41f749 100644 --- a/Release/src/http/listener/http_server_asio.cpp +++ b/Release/src/http/listener/http_server_asio.cpp @@ -38,6 +38,7 @@ using namespace boost::asio; using namespace boost::asio::ip; #define CRLF std::string("\r\n") +#define CRLFCRLF std::string("\r\n\r\n") namespace web { @@ -144,7 +145,7 @@ struct crlf_nonascii_searcher_t } return std::make_pair(excluded, false); } -} crlf_nonascii_searcher; +} crlfcrlf_nonascii_searcher; }}}}} namespace boost @@ -205,14 +206,14 @@ void connection::start_request_response() if (m_ssl_stream) { - boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLF, [this](const boost::system::error_code& ec, std::size_t) + boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLFCRLF, [this](const boost::system::error_code& ec, std::size_t) { this->handle_http_line(ec); }); } else { - boost::asio::async_read_until(*m_socket, m_request_buf, crlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t) + boost::asio::async_read_until(*m_socket, m_request_buf, crlfcrlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t) { this->handle_http_line(ec); });