1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
// Copyright Maarten L. Hekkelman, Radboud University 2008-2013.
// Copyright Maarten L. Hekkelman, 2014-2022
// 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)
#pragma once
/// \file
/// definition of the zeep::http::{request,reply}_parser classes that parse HTTP input/output
#include <zeep/config.hpp>
#include <tuple>
#include <boost/logic/tribool.hpp>
#include <zeep/http/request.hpp>
#include <zeep/http/reply.hpp>
namespace zeep::http
{
/// An HTTP message parser with support for Transfer-Encoding: Chunked
class parser
{
public:
virtual ~parser() {}
virtual void reset();
boost::tribool parse_header_lines(char ch);
boost::tribool parse_chunk(char ch);
boost::tribool parse_footer(char ch);
boost::tribool parse_content(char ch);
protected:
typedef boost::tribool (parser::*state_parser)(char ch);
parser();
state_parser m_parser;
int m_state;
unsigned int m_chunk_size;
std::string m_data;
std::string m_uri;
std::string m_method;
bool m_parsing_content;
bool m_collect_payload;
int m_http_version_major, m_http_version_minor;
std::vector<header> m_headers;
std::string m_payload;
};
class request_parser : public parser
{
public:
request_parser();
boost::tribool parse(std::streambuf& text);
request get_request();
private:
boost::tribool parse_initial_line(char ch);
};
class reply_parser : public parser
{
public:
reply_parser();
boost::tribool parse(std::streambuf& text);
reply get_reply();
virtual void reset();
private:
boost::tribool parse_initial_line(char ch);
int m_status = 0;
std::string m_status_line;
};
} // namespace zeep::http
|