Program Listing for File http_request_parser.hpp
↰ Return to documentation for file (/tmp/ws/src/async_web_server_cpp/include/async_web_server_cpp/http_request_parser.hpp
)
//
// http_request_parser.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef CPP_WEB_SERVER_HTTP_REQUEST_PARSER_HPP
#define CPP_WEB_SERVER_HTTP_REQUEST_PARSER_HPP
#include "async_web_server_cpp/http_request.hpp"
#include <boost/logic/tribool.hpp>
#include <boost/tuple/tuple.hpp>
namespace async_web_server_cpp
{
class HttpRequestParser
{
public:
HttpRequestParser();
void reset();
template<typename InputIterator>
boost::tuple<boost::tribool, InputIterator>
parse(HttpRequest& req, InputIterator begin, InputIterator end)
{
while (begin != end)
{
boost::tribool result = consume(req, *begin++);
if (result || !result)
return boost::make_tuple(result, begin);
}
boost::tribool result = boost::indeterminate;
return boost::make_tuple(result, begin);
}
private:
boost::tribool consume(HttpRequest& req, char input);
static bool is_char(int c);
static bool is_ctl(int c);
static bool is_tspecial(int c);
static bool is_digit(int c);
enum state
{
method_start,
method,
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,
expecting_newline_3
} state_;
};
} // namespace async_web_server_cpp
#endif