Skip to content

Commit

Permalink
Fix header reading on linux listener using HTTPS.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Simon Lepasteur committed Mar 31, 2016
1 parent 29ba42e commit a148540
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Release/src/http/listener/http_server_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -144,7 +145,7 @@ struct crlf_nonascii_searcher_t
}
return std::make_pair(excluded, false);
}
} crlf_nonascii_searcher;
} crlfcrlf_nonascii_searcher;
}}}}}

namespace boost
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit a148540

Please sign in to comment.