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
14 #include <boost/logic/tribool.hpp>
15 #include <boost/tuple/tuple.hpp>
22 /// Parser for incoming requests.
26 /// Construct ready to parse the request method.
29 /// Reset to initial parser state.
32 /// Parse some data. The tribool return value is true when a complete request
33 /// has been parsed, false if the data is invalid, indeterminate when more
34 /// data is required. The InputIterator return value indicates how much of the
35 /// input has been consumed.
36 template <typename InputIterator>
37 boost::tuple<boost::tribool, InputIterator> parse(request& req,
38 InputIterator begin, InputIterator end)
42 boost::tribool result = consume(req, *begin++);
43 if (result || !result)
44 return boost::make_tuple(result, begin);
46 boost::tribool result = boost::indeterminate;
47 return boost::make_tuple(result, begin);
51 /// Handle the next character of input.
52 boost::tribool consume(request& req, char input);
54 /// Check if a byte is an HTTP character.
55 static bool is_char(int c);
57 /// Check if a byte is an HTTP control character.
58 static bool is_ctl(int c);
60 /// Check if a byte is defined as an HTTP tspecial character.
61 static bool is_tspecial(int c);
63 /// Check if a byte is a digit.
64 static bool is_digit(int c);
66 /// The current state of the parser.
77 http_version_major_start,
79 http_version_minor_start,
85 space_before_header_value,
95 #endif // HTTP_REQUEST_PARSER_HPP