From 6d9cd504a0c1b3dec325f174bc7ed809edd533d0 Mon Sep 17 00:00:00 2001 From: Neil Buckman Date: Thu, 12 Feb 2015 08:01:46 +0000 Subject: [PATCH 1/2] Made the request parser a member of the Connection Previously, the request parser was created on demand...but this could cause requests to be flagged as bad requests if the string length was large enough to cause the string to be split up into chunks by boost's read_some method. --- server/connection.cpp | 4 +++- server/connection.hpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/connection.cpp b/server/connection.cpp index 0f16f465f..aee7f4e56 100644 --- a/server/connection.cpp +++ b/server/connection.cpp @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "connection.hpp" #include "request_handler.hpp" #include "request_parser.hpp" +//#include "../util/simple_logger.hpp" #include #include @@ -68,7 +69,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t compression_type compression_type(no_compression); osrm::tribool result; std::tie(result, compression_type) = - RequestParser().parse(current_request, incoming_data_buffer.data(), + request_parser.parse(current_request, incoming_data_buffer.data(), incoming_data_buffer.data() + bytes_transferred); // the request has been parsed @@ -126,6 +127,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t else { // we don't have a result yet, so continue reading + //SimpleLogger().Write(logDEBUG) << "Continue reading..."; TCP_socket.async_read_some( boost::asio::buffer(incoming_data_buffer), strand.wrap(boost::bind(&Connection::handle_read, this->shared_from_this(), diff --git a/server/connection.hpp b/server/connection.hpp index d549f6e44..119289080 100644 --- a/server/connection.hpp +++ b/server/connection.hpp @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "http/compression_type.hpp" #include "http/reply.hpp" #include "http/request.hpp" +#include "request_parser.hpp" #include #include @@ -82,6 +83,7 @@ class Connection : public std::enable_shared_from_this boost::asio::io_service::strand strand; boost::asio::ip::tcp::socket TCP_socket; RequestHandler &request_handler; + RequestParser request_parser; boost::array incoming_data_buffer; request current_request; reply current_reply; From fa638ae3a051ffd7fa479349db09199fdb691103 Mon Sep 17 00:00:00 2001 From: Neil Buckman Date: Thu, 12 Feb 2015 09:55:13 +0000 Subject: [PATCH 2/2] Removed debug logging --- server/connection.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/connection.cpp b/server/connection.cpp index aee7f4e56..9d8b7a76e 100644 --- a/server/connection.cpp +++ b/server/connection.cpp @@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "connection.hpp" #include "request_handler.hpp" #include "request_parser.hpp" -//#include "../util/simple_logger.hpp" #include #include @@ -127,7 +126,6 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t else { // we don't have a result yet, so continue reading - //SimpleLogger().Write(logDEBUG) << "Continue reading..."; TCP_socket.async_read_some( boost::asio::buffer(incoming_data_buffer), strand.wrap(boost::bind(&Connection::handle_read, this->shared_from_this(),