Skip to content

Commit a148540

Browse files
author
Simon Lepasteur
committed
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.
1 parent 29ba42e commit a148540

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Release/src/http/listener/http_server_asio.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using namespace boost::asio;
3838
using namespace boost::asio::ip;
3939

4040
#define CRLF std::string("\r\n")
41+
#define CRLFCRLF std::string("\r\n\r\n")
4142

4243
namespace web
4344
{
@@ -144,7 +145,7 @@ struct crlf_nonascii_searcher_t
144145
}
145146
return std::make_pair(excluded, false);
146147
}
147-
} crlf_nonascii_searcher;
148+
} crlfcrlf_nonascii_searcher;
148149
}}}}}
149150

150151
namespace boost
@@ -205,14 +206,14 @@ void connection::start_request_response()
205206

206207
if (m_ssl_stream)
207208
{
208-
boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLF, [this](const boost::system::error_code& ec, std::size_t)
209+
boost::asio::async_read_until(*m_ssl_stream, m_request_buf, CRLFCRLF, [this](const boost::system::error_code& ec, std::size_t)
209210
{
210211
this->handle_http_line(ec);
211212
});
212213
}
213214
else
214215
{
215-
boost::asio::async_read_until(*m_socket, m_request_buf, crlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t)
216+
boost::asio::async_read_until(*m_socket, m_request_buf, crlfcrlf_nonascii_searcher, [this](const boost::system::error_code& ec, std::size_t)
216217
{
217218
this->handle_http_line(ec);
218219
});

0 commit comments

Comments
 (0)