2015-01-27 06:35:29 -05:00
|
|
|
#ifndef REQUEST_PARSER_HPP
|
|
|
|
#define REQUEST_PARSER_HPP
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "server/http/compression_type.hpp"
|
|
|
|
#include "server/http/header.hpp"
|
2015-01-23 11:46:40 -05:00
|
|
|
|
2015-01-23 11:14:12 -05:00
|
|
|
#include <tuple>
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace server
|
2014-05-07 11:14:57 -04:00
|
|
|
{
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
namespace http
|
|
|
|
{
|
2015-01-27 05:45:33 -05:00
|
|
|
struct request;
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
|
2014-05-07 11:14:57 -04:00
|
|
|
class RequestParser
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 12:29:56 -05:00
|
|
|
RequestParser();
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2016-01-28 18:43:19 -05:00
|
|
|
std::tuple<RequestStatus, http::compression_type>
|
2016-01-05 10:51:13 -05:00
|
|
|
parse(http::request ¤t_request, char *begin, char *end);
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2016-01-28 18:43:19 -05:00
|
|
|
enum class RequestStatus : char
|
|
|
|
{
|
|
|
|
valid,
|
|
|
|
invalid,
|
|
|
|
indeterminate
|
|
|
|
};
|
|
|
|
|
2014-05-07 11:14:57 -04:00
|
|
|
private:
|
2016-01-28 18:43:19 -05:00
|
|
|
RequestStatus consume(http::request ¤t_request, const char input);
|
2012-04-20 10:19:56 -04:00
|
|
|
|
2015-01-27 03:58:26 -05:00
|
|
|
bool is_char(const int character) const;
|
2012-05-03 05:07:53 -04:00
|
|
|
|
2015-01-27 03:58:26 -05:00
|
|
|
bool is_CTL(const int character) const;
|
2012-06-08 04:12:42 -04:00
|
|
|
|
2015-01-27 03:58:26 -05:00
|
|
|
bool is_special(const int character) const;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-27 03:58:26 -05:00
|
|
|
bool is_digit(const int character) const;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-26 07:20:22 -05:00
|
|
|
enum class internal_state : unsigned char
|
2015-01-23 11:14:12 -05:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
space_before_header_value,
|
|
|
|
header_value,
|
|
|
|
expecting_newline_2,
|
2015-05-27 09:40:10 -04:00
|
|
|
expecting_newline_3,
|
|
|
|
post_O,
|
|
|
|
post_S,
|
|
|
|
post_T,
|
|
|
|
post_request
|
2015-01-26 07:20:22 -05:00
|
|
|
} state;
|
2011-02-11 11:12:37 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
http::header current_header;
|
|
|
|
http::compression_type selected_compression;
|
2015-05-27 09:40:10 -04:00
|
|
|
bool is_post_header;
|
2015-05-31 12:50:46 -04:00
|
|
|
int content_length;
|
2011-01-09 16:42:27 -05:00
|
|
|
};
|
2016-01-05 10:51:13 -05:00
|
|
|
}
|
|
|
|
}
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-27 06:35:29 -05:00
|
|
|
#endif // REQUEST_PARSER_HPP
|