5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef HTTP_REQUEST_PARSER_HPP
12 #define HTTP_REQUEST_PARSER_HPP
21 /// Parser for incoming requests.
25 /// Construct ready to parse the request method.
28 /// Reset to initial parser state.
32 enum result_type { good, bad, indeterminate };
34 /// Parse some data. The enum return value is good when a complete request has
35 /// been parsed, bad if the data is invalid, indeterminate when more data is
36 /// required. The InputIterator return value indicates how much of the input
37 /// has been consumed.
38 template <typename InputIterator>
39 std::tuple<result_type, InputIterator> parse(request& req,
40 InputIterator begin, InputIterator end)
44 result_type result = consume(req, *begin++);
45 if (result == good || result == bad)
46 return std::make_tuple(result, begin);
48 return std::make_tuple(indeterminate, begin);
52 /// Handle the next character of input.
53 result_type consume(request& req, char input);
55 /// Check if a byte is an HTTP character.
56 static bool is_char(int c);
58 /// Check if a byte is an HTTP control character.
59 static bool is_ctl(int c);
61 /// Check if a byte is defined as an HTTP tspecial character.
62 static bool is_tspecial(int c);
64 /// Check if a byte is a digit.
65 static bool is_digit(int c);
67 /// The current state of the parser.
78 http_version_major_start,
80 http_version_minor_start,
86 space_before_header_value,
96 #endif // HTTP_REQUEST_PARSER_HPP