Fix bug with large HTTP requests leading to Bad Request in osrm-routed. (#6403)
This commit is contained in:
committed by
GitHub
parent
4026ed54c0
commit
d143de597d
@@ -12,10 +12,16 @@ namespace osrm
|
||||
namespace server
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
const size_t CHUNK_SIZE = 8192;
|
||||
|
||||
} // namespace
|
||||
Connection::Connection(boost::asio::io_context &io_context, RequestHandler &handler)
|
||||
: strand(boost::asio::make_strand(io_context)), TCP_socket(strand), timer(strand),
|
||||
request_handler(handler), http_request_parser(std::make_optional<RequestParser>())
|
||||
{
|
||||
http_request_parser->header_limit(std::numeric_limits<std::uint32_t>::max());
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket &Connection::socket() { return TCP_socket; }
|
||||
@@ -59,7 +65,8 @@ void Connection::start()
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::handle_read(const boost::system::error_code &error, std::size_t bytes_transferred)
|
||||
void Connection::handle_read(const boost::system::error_code &error,
|
||||
std::size_t /*bytes_transferred*/)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
@@ -79,7 +86,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
}
|
||||
|
||||
boost::beast::error_code ec;
|
||||
http_request_parser->put(boost::asio::buffer(incoming_data_buffer, bytes_transferred), ec);
|
||||
http_request_parser->put(boost::asio::buffer(incoming_data_buffer), ec);
|
||||
// no error detected, let's parse the request
|
||||
http::compression_type compression_type(http::no_compression);
|
||||
|
||||
@@ -87,12 +94,15 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
{
|
||||
if (ec == boost::beast::http::error::need_more)
|
||||
{
|
||||
const auto current_size = incoming_data_buffer.size();
|
||||
incoming_data_buffer.resize(incoming_data_buffer.size() + CHUNK_SIZE, 0);
|
||||
// we don't have a result yet, so continue reading
|
||||
TCP_socket.async_read_some(boost::asio::buffer(incoming_data_buffer),
|
||||
boost::bind(&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
TCP_socket.async_read_some(
|
||||
boost::asio::buffer(incoming_data_buffer.data() + current_size, CHUNK_SIZE),
|
||||
boost::bind(&Connection::handle_read,
|
||||
this->shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,7 +193,8 @@ void Connection::handle_write(const boost::system::error_code &error)
|
||||
current_request = http::request();
|
||||
current_reply = http::reply();
|
||||
http_request_parser.emplace();
|
||||
incoming_data_buffer = boost::array<char, 8192>();
|
||||
http_request_parser->header_limit(std::numeric_limits<std::uint32_t>::max());
|
||||
incoming_data_buffer.resize(CHUNK_SIZE, 0);
|
||||
output_buffer.clear();
|
||||
this->start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user