Use Boost.Beast to parse HTTP request (#6294)
This commit is contained in:
committed by
GitHub
parent
00816722dd
commit
e7185b4bcb
@@ -4,14 +4,15 @@
|
||||
#include "server/http/compression_type.hpp"
|
||||
#include "server/http/reply.hpp"
|
||||
#include "server/http/request.hpp"
|
||||
#include "server/request_parser.hpp"
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
// workaround for incomplete std::shared_ptr compatibility in old boost versions
|
||||
@@ -47,6 +48,7 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
void start();
|
||||
|
||||
private:
|
||||
using RequestParser = boost::beast::http::request_parser<boost::beast::http::string_body>;
|
||||
void handle_read(const boost::system::error_code &e, std::size_t bytes_transferred);
|
||||
|
||||
/// Handle completion of a write operation.
|
||||
@@ -60,11 +62,13 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
||||
const http::compression_type compression_type);
|
||||
|
||||
void fill_request(const RequestParser::value_type &httpMessage, http::request &request);
|
||||
|
||||
boost::asio::strand<boost::asio::io_context::executor_type> strand;
|
||||
boost::asio::ip::tcp::socket TCP_socket;
|
||||
boost::asio::deadline_timer timer;
|
||||
RequestHandler &request_handler;
|
||||
RequestParser request_parser;
|
||||
std::optional<RequestParser> http_request_parser;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
http::request current_request;
|
||||
http::reply current_reply;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
#ifndef REQUEST_PARSER_HPP
|
||||
#define REQUEST_PARSER_HPP
|
||||
|
||||
#include "server/http/compression_type.hpp"
|
||||
#include "server/http/header.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace server
|
||||
{
|
||||
|
||||
namespace http
|
||||
{
|
||||
struct request;
|
||||
}
|
||||
|
||||
class RequestParser
|
||||
{
|
||||
public:
|
||||
RequestParser();
|
||||
|
||||
enum class RequestStatus : char
|
||||
{
|
||||
valid,
|
||||
invalid,
|
||||
indeterminate
|
||||
};
|
||||
|
||||
std::tuple<RequestStatus, http::compression_type>
|
||||
parse(http::request ¤t_request, char *begin, char *end);
|
||||
|
||||
private:
|
||||
RequestStatus consume(http::request ¤t_request, const char input);
|
||||
|
||||
bool is_char(const int character) const;
|
||||
|
||||
bool is_CTL(const int character) const;
|
||||
|
||||
bool is_special(const int character) const;
|
||||
|
||||
bool is_digit(const int character) const;
|
||||
|
||||
enum class internal_state : unsigned char
|
||||
{
|
||||
method_start,
|
||||
method,
|
||||
uri_start,
|
||||
uri,
|
||||
http_version_h,
|
||||
http_version_t_1,
|
||||
http_version_t_2,
|
||||
http_version_p,
|
||||
http_version_slash,
|
||||
http_version_major_start,
|
||||
http_version_major,
|
||||
http_version_minor_start,
|
||||
http_version_minor,
|
||||
expecting_newline_1,
|
||||
header_line_start,
|
||||
header_lws,
|
||||
header_name,
|
||||
header_value,
|
||||
expecting_newline_2,
|
||||
expecting_newline_3
|
||||
} state;
|
||||
|
||||
http::header current_header;
|
||||
http::compression_type selected_compression;
|
||||
};
|
||||
} // namespace server
|
||||
} // namespace osrm
|
||||
|
||||
#endif // REQUEST_PARSER_HPP
|
||||
Reference in New Issue
Block a user