Files
boost_beast/include/beast/http/basic_parser_v1.hpp
T

991 lines
27 KiB
C++
Raw Normal View History

2016-04-19 20:29:16 -04:00
//
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail 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)
//
2014-08-26 09:25:19 -07:00
#ifndef BEAST_HTTP_BASIC_PARSER_v1_HPP
#define BEAST_HTTP_BASIC_PARSER_v1_HPP
2014-08-26 09:25:19 -07:00
2016-04-25 05:27:34 -04:00
#include <beast/http/message.hpp>
#include <beast/http/parse_error.hpp>
#include <beast/http/rfc7230.hpp>
#include <beast/http/detail/basic_parser_v1.hpp>
#include <boost/asio/buffer.hpp>
2016-09-25 12:17:32 -04:00
#include <boost/assert.hpp>
2016-04-25 05:27:34 -04:00
#include <array>
#include <climits>
2014-08-26 09:25:19 -07:00
#include <cstdint>
2016-04-19 20:29:16 -04:00
#include <type_traits>
2014-08-26 09:25:19 -07:00
namespace beast {
namespace http {
2016-04-25 05:27:34 -04:00
namespace parse_flag {
enum values
{
chunked = 1,
connection_keep_alive = 2,
connection_close = 4,
connection_upgrade = 8,
trailing = 16,
upgrade = 32,
skipbody = 64,
contentlength = 128
2016-04-25 05:27:34 -04:00
};
} // parse_flag
/** Headers maximum size option.
Sets the maximum number of cumulative bytes allowed
including all header octets. A value of zero indicates
no limit on the number of header octets
The default headers maximum size is 16KB (16,384 bytes).
@note Objects of this type are passed to @ref set_option.
*/
struct headers_max_size
{
std::size_t value;
explicit
headers_max_size(std::size_t v)
: value(v)
{
}
};
/** Body maximum size option.
Sets the maximum number of cumulative bytes allowed including
all body octets. Octets in chunk-encoded bodies are counted
after decoding. A value of zero indicates no limit on
the number of body octets.
The default body maximum size for requests is 4MB (four
megabytes or 4,194,304 bytes) and unlimited for responses.
@note Objects of this type are passed to @ref set_option.
*/
struct body_max_size
{
std::size_t value;
explicit
body_max_size(std::size_t v)
: value(v)
{
}
};
2016-10-10 07:55:39 -04:00
/** A value indicating how the parser should treat the body.
This value is returned from the `on_headers` callback in
the derived class. It controls what the parser does next
in terms of the message body.
*/
enum class body_what
{
/** The parser should expect a body, keep reading.
*/
normal,
/** Skip parsing of the body.
When returned by `on_headers` this causes parsing to
complete and control to return to the caller. This
could be used when sending a response to a HEAD
request, for example.
*/
skip,
/** The message represents an UPGRADE request.
When returned by `on_headers` this causes parsing
to complete and control to return to the caller.
*/
upgrade,
/** Suspend parsing before reading the body.
When returned by `on_headers` this causes parsing to
pause. Control is returned to the caller, and the parser
state is preserved such that a subsequent call to the
parser will begin reading the message body.
This could be used by callers to inspect the HTTP
headers before committing to read the body. For example,
to choose the body type based on the headers. Or to
respond to an Expect: 100-continue request.
*/
pause
};
/// The value returned when no content length is known or applicable.
static std::uint64_t constexpr no_content_length =
std::numeric_limits<std::uint64_t>::max();
2016-04-30 10:29:39 -04:00
/** A parser for decoding HTTP/1 wire format messages.
2016-03-11 06:40:37 -05:00
2016-04-30 10:29:39 -04:00
This parser is designed to efficiently parse messages in the
HTTP/1 wire format. It allocates no memory and uses minimal
state. It will handle chunked encoding and it understands the
semantics of the Connection and Content-Length header fields.
The interface uses CRTP (Curiously Recurring Template Pattern).
To use this class, derive from basic_parser. When bytes are
presented, the implementation will make a series of zero or
more calls to derived class members functions (referred to as
"callbacks" from here on) matching a specific signature.
Callbacks are detected through SFINAE. The derived class may
2016-10-15 10:39:01 -04:00
implement as few or as many of the members as needed. Callbacks
may not throw exceptions. These are the signatures of the
callbacks:<br>
2016-04-30 10:29:39 -04:00
@li `void on_start(error_code&)`
Called when the first valid octet of a new message is received
2016-03-11 06:40:37 -05:00
@li `void on_method(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the Request-Method
2016-03-11 06:40:37 -05:00
@li `void on_uri(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the Request-URI
2016-03-11 06:40:37 -05:00
@li `void on_reason(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the reason-phrase
2016-03-11 06:40:37 -05:00
@li `void on_request(error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called after the entire Request-Line has been parsed successfully.
2016-03-11 06:40:37 -05:00
@li `void on_response(error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called after the entire Response-Line has been parsed successfully.
2016-03-11 06:40:37 -05:00
@li `void on_field(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the current header field.
2016-03-11 06:40:37 -05:00
@li `void on_value(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the current header value.
2016-03-11 06:40:37 -05:00
2016-10-10 07:55:39 -04:00
@li `body_what on_headers(std::uint64_t content_length, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called when all the headers have been parsed successfully.
2016-03-11 06:40:37 -05:00
@li `void on_body(boost::string_ref const&, error_code&)`
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
Called for each piece of the body. If the headers indicated
chunked encoding, the chunk encoding is removed from the
buffer before being passed to the callback.
@li `void on_complete(error_code&)`
2016-04-25 05:27:34 -04:00
Called when the entire message has been parsed successfully.
2016-10-15 09:29:14 -04:00
At this point, @ref complete returns `true`, and the parser
is ready to parse another message if @ref keep_alive would
return `true`.
2016-04-25 05:27:34 -04:00
The return value of `on_headers` is special, it controls whether
2016-10-10 07:55:39 -04:00
or not the parser should expect a body. See @ref body_what for
choices of the return value.
2016-03-11 06:40:37 -05:00
The parser uses traits to determine if the callback is possible.
2016-10-10 07:55:39 -04:00
If the @b Derived type omits one or more callbacks, they are simply
skipped with no compilation error. The default behavior of `on_body`
2016-04-25 05:27:34 -04:00
when the derived class does not provide the member, is to specify that
the body should not be skipped.
If a callback sets an error, parsing stops at the current octet
and the error is returned to the caller.
2016-04-30 10:29:39 -04:00
@tparam isRequest A `bool` indicating whether the parser will be
presented with request or response message.
2016-10-10 07:55:39 -04:00
@tparam Derived The derived class type. This is part of the
Curiously Recurring Template Pattern interface.
2016-03-11 06:40:37 -05:00
*/
2016-04-25 05:27:34 -04:00
template<bool isRequest, class Derived>
class basic_parser_v1 : public detail::parser_base
2014-08-26 09:25:19 -07:00
{
2016-04-25 05:27:34 -04:00
private:
using self = basic_parser_v1;
2016-04-25 05:27:34 -04:00
typedef void(self::*pmf_t)(error_code&, boost::string_ref const&);
enum field_state : std::uint8_t
{
h_general = 0,
h_C,
h_CO,
h_CON,
h_matching_connection,
h_matching_proxy_connection,
h_matching_content_length,
h_matching_transfer_encoding,
h_matching_upgrade,
h_connection,
h_content_length0,
2016-04-25 05:27:34 -04:00
h_content_length,
h_content_length_ows,
2016-04-25 05:27:34 -04:00
h_transfer_encoding,
h_upgrade,
h_matching_transfer_encoding_chunked,
h_matching_transfer_encoding_general,
2016-04-25 05:27:34 -04:00
h_matching_connection_keep_alive,
h_matching_connection_close,
h_matching_connection_upgrade,
h_transfer_encoding_chunked,
h_transfer_encoding_chunked_ows,
2016-04-25 05:27:34 -04:00
h_connection_keep_alive,
h_connection_keep_alive_ows,
2016-04-25 05:27:34 -04:00
h_connection_close,
h_connection_close_ows,
2016-04-25 05:27:34 -04:00
h_connection_upgrade,
h_connection_upgrade_ows,
h_connection_token,
h_connection_token_ows
2016-04-25 05:27:34 -04:00
};
std::size_t h_max_;
std::size_t h_left_;
std::size_t b_max_;
std::size_t b_left_;
2016-04-25 05:27:34 -04:00
std::uint64_t content_length_;
pmf_t cb_;
state s_ : 8;
unsigned flags_ : 8;
unsigned fs_ : 8;
unsigned pos_ : 8; // position in field state
unsigned http_major_ : 16;
unsigned http_minor_ : 16;
unsigned status_code_ : 16;
bool upgrade_ : 1; // true if parser exited for upgrade
2014-08-26 09:25:19 -07:00
public:
2016-04-25 05:27:34 -04:00
/// Copy constructor.
basic_parser_v1(basic_parser_v1 const&) = default;
2014-08-26 09:25:19 -07:00
2016-04-25 05:27:34 -04:00
/// Copy assignment.
basic_parser_v1& operator=(basic_parser_v1 const&) = default;
2016-03-11 06:40:37 -05:00
/// Default constructor
basic_parser_v1();
/** Set options on the parser.
@param args One or more parser options to set.
*/
#if GENERATING_DOCS
template<class... Args>
void
set_option(Args&&... args)
#else
template<class A1, class A2, class... An>
void
set_option(A1&& a1, A2&& a2, An&&... an)
#endif
2016-04-25 05:27:34 -04:00
{
set_option(std::forward<A1>(a1));
set_option(std::forward<A2>(a2),
std::forward<An>(an)...);
}
/// Set the headers maximum size option
void
set_option(headers_max_size const& o)
{
h_max_ = o.value;
h_left_ = h_max_;
}
/// Set the body maximum size option
void
set_option(body_max_size const& o)
{
b_max_ = o.value;
b_left_ = b_max_;
2016-04-25 05:27:34 -04:00
}
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
/// Returns internal flags associated with the parser.
unsigned
flags() const
{
return flags_;
}
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
/** Returns `true` if the message end is indicated by eof.
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
This function returns true if the semantics of the message require
that the end of the message is signaled by an end of file. For
example, if the message is a HTTP/1.0 message and the Content-Length
is unspecified, the end of the message is indicated by an end of file.
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
@return `true` if write_eof must be used to indicate the message end.
2014-08-26 09:25:19 -07:00
*/
bool
2016-04-25 05:27:34 -04:00
needs_eof() const
2014-08-26 09:25:19 -07:00
{
2016-04-25 05:27:34 -04:00
return needs_eof(
std::integral_constant<bool, isRequest>{});
}
/** Returns the major HTTP version number.
Examples:
* Returns 1 for HTTP/1.1
* Returns 1 for HTTP/1.0
@return The HTTP major version number.
*/
unsigned
http_major() const
{
return http_major_;
}
/** Returns the minor HTTP version number.
Examples:
* Returns 1 for HTTP/1.1
* Returns 0 for HTTP/1.0
@return The HTTP minor version number.
*/
unsigned
http_minor() const
{
return http_minor_;
}
/** Returns `true` if the message is an upgrade message.
A value of `true` indicates that the parser has successfully
completed parsing a HTTP upgrade message.
@return `true` if the message is an upgrade message.
*/
bool
upgrade() const
{
return upgrade_;
}
/** Returns the numeric HTTP Status-Code of a response.
@return The Status-Code.
*/
unsigned
status_code() const
{
return status_code_;
}
/** Returns `true` if the connection should be kept open.
@note This function is only valid to call when the parser
is complete.
*/
bool
keep_alive() const;
/** Returns `true` if the parse has completed succesfully.
When the parse has completed successfully, and the semantics
of the parsed message indicate that the connection is still
active, a subsequent call to `write` will begin parsing a
new message.
@return `true` If the parsing has completed successfully.
*/
bool
complete() const
{
2016-04-30 10:29:39 -04:00
return s_ == s_restart || s_ == s_closed_complete;
2014-08-26 09:25:19 -07:00
}
/** Write a sequence of buffers to the parser.
2014-08-26 09:25:19 -07:00
2016-04-25 05:27:34 -04:00
@param buffers An object meeting the requirements of
ConstBufferSequence that represents the input sequence.
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
@param ec Set to the error, if any error occurred.
2016-03-11 06:40:37 -05:00
@return The number of bytes consumed in the input sequence.
2014-08-26 09:25:19 -07:00
*/
template<class ConstBufferSequence>
2016-05-27 11:17:53 -04:00
#if GENERATING_DOCS
2016-03-11 06:40:37 -05:00
std::size_t
2016-05-27 11:17:53 -04:00
#else
typename std::enable_if<
! std::is_convertible<ConstBufferSequence,
boost::asio::const_buffer>::value,
std::size_t>::type
2016-05-27 11:17:53 -04:00
#endif
2016-04-25 05:27:34 -04:00
write(ConstBufferSequence const& buffers, error_code& ec);
2016-03-11 06:40:37 -05:00
/** Write a single buffer of data to the parser.
2016-03-11 06:40:37 -05:00
@param buffer The buffer to write.
2016-03-11 06:40:37 -05:00
@param ec Set to the error, if any error occurred.
@return The number of bytes consumed in the buffer.
2016-03-11 06:40:37 -05:00
*/
std::size_t
write(boost::asio::const_buffer const& buffer, error_code& ec);
2014-08-26 09:25:19 -07:00
/** Called to indicate the end of file.
2016-03-11 06:40:37 -05:00
2014-08-26 09:25:19 -07:00
HTTP needs to know where the end of the stream is. For example,
sometimes servers send responses without Content-Length and
expect the client to consume input (for the body) until EOF.
Callbacks and errors will still be processed as usual.
2016-03-11 06:40:37 -05:00
2014-08-26 09:25:19 -07:00
@note This is typically called when a socket read returns eof.
*/
void
2016-03-11 06:40:37 -05:00
write_eof(error_code& ec);
2014-08-26 09:25:19 -07:00
private:
2016-03-11 06:40:37 -05:00
Derived&
impl()
{
return *static_cast<Derived*>(this);
}
2014-08-26 09:25:19 -07:00
2016-03-11 06:40:37 -05:00
void
reset(std::true_type)
2016-03-11 06:40:37 -05:00
{
2016-04-25 05:27:34 -04:00
s_ = s_req_start;
2016-03-11 06:40:37 -05:00
}
void
reset(std::false_type)
2016-03-11 06:40:37 -05:00
{
2016-04-25 05:27:34 -04:00
s_ = s_res_start;
2016-03-11 06:40:37 -05:00
}
void
reset()
{
h_left_ = h_max_;
b_left_ = b_max_;
reset(std::integral_constant<bool, isRequest>{});
}
void
init(std::true_type)
{
// 16KB max headers, 4MB max body
h_max_ = 16 * 1024;
b_max_ = 4 * 1024 * 1024;
}
void
init(std::false_type)
{
// 16KB max headers, unlimited body
h_max_ = 16 * 1024;
b_max_ = 0;
}
void
init()
{
init(std::integral_constant<bool, isRequest>{});
reset();
}
2016-03-11 06:40:37 -05:00
bool
2016-04-25 05:27:34 -04:00
needs_eof(std::true_type) const;
bool
needs_eof(std::false_type) const;
2016-04-30 10:29:39 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_start_t
2016-04-30 10:29:39 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_start(
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-30 10:29:39 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_start =
std::integral_constant<bool, check_on_start_t<C>::value>;
2016-04-30 10:29:39 -04:00
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_method_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_method(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_method =
std::integral_constant<bool, check_on_method_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_uri_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_uri(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_uri =
std::integral_constant<bool, check_on_uri_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_reason_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_reason(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_reason =
std::integral_constant<bool, check_on_reason_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_request_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_request(
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_request =
std::integral_constant<bool, check_on_request_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_response_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_response(
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_response =
std::integral_constant<bool, check_on_response_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_field_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_uri(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_field =
std::integral_constant<bool, check_on_field_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_value_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_uri(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_value =
std::integral_constant<bool, check_on_value_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_headers_t
2016-04-27 07:02:51 -04:00
{
2016-10-10 07:55:39 -04:00
template<class T, class R = std::is_convertible<body_what,
2016-04-27 07:02:51 -04:00
decltype(std::declval<T>().on_headers(
std::declval<std::uint64_t>(), std::declval<error_code&>()))>>
2016-04-27 07:02:51 -04:00
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_headers =
std::integral_constant<bool, check_on_headers_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_body_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_body(
std::declval<boost::string_ref const&>(),
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_body =
std::integral_constant<bool, check_on_body_t<C>::value>;
2016-04-27 07:02:51 -04:00
template<class C>
2016-10-10 08:28:12 -04:00
class check_on_complete_t
2016-04-27 07:02:51 -04:00
{
template<class T, class R =
decltype(std::declval<T>().on_complete(
std::declval<error_code&>()),
std::true_type{})>
static R check(int);
2016-08-26 08:01:44 -04:00
template<class>
2016-04-27 07:02:51 -04:00
static std::false_type check(...);
using type = decltype(check<C>(0));
public:
static bool const value = type::value;
};
template<class C>
2016-10-10 08:28:12 -04:00
using check_on_complete =
std::integral_constant<bool, check_on_complete_t<C>::value>;
#undef BEAST_HAS_MEMBER
2016-04-27 07:02:51 -04:00
2016-04-30 10:29:39 -04:00
void call_on_start(error_code& ec, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_start<Derived>::value,
"on_start requirements not met");
2016-04-30 10:29:39 -04:00
impl().on_start(ec);
}
void call_on_start(error_code& ec, std::false_type)
{
}
void call_on_start(error_code& ec)
{
2016-10-10 08:28:12 -04:00
call_on_start(ec, std::is_member_function_pointer<
decltype(&Derived::on_start)>{});
2016-04-30 10:29:39 -04:00
}
2016-04-25 05:27:34 -04:00
void call_on_method(error_code& ec,
boost::string_ref const& s, std::true_type)
2016-03-11 06:40:37 -05:00
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_method<Derived>::value,
"on_method requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_method(s, ec);
2016-03-11 06:40:37 -05:00
}
2016-04-25 05:27:34 -04:00
void call_on_method(error_code&,
boost::string_ref const&, std::false_type)
2016-03-11 06:40:37 -05:00
{
}
2016-04-25 05:27:34 -04:00
void call_on_method(error_code& ec,
boost::string_ref const& s)
2016-03-11 06:40:37 -05:00
{
if(! h_max_ || s.size() <= h_left_)
{
h_left_ -= s.size();
call_on_method(ec, s, std::integral_constant<bool,
2016-10-10 08:28:12 -04:00
isRequest && std::is_member_function_pointer<
decltype(&Derived::on_method)>::value>{});
}
else
{
ec = parse_error::headers_too_big;
}
2016-03-11 06:40:37 -05:00
}
2016-04-25 05:27:34 -04:00
void call_on_uri(error_code& ec,
boost::string_ref const& s, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_uri<Derived>::value,
"on_uri requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_uri(s, ec);
}
void call_on_uri(error_code&,
boost::string_ref const&, std::false_type)
2016-03-11 06:40:37 -05:00
{
}
2016-04-25 05:27:34 -04:00
void call_on_uri(error_code& ec, boost::string_ref const& s)
2016-03-11 06:40:37 -05:00
{
if(! h_max_ || s.size() <= h_left_)
{
h_left_ -= s.size();
call_on_uri(ec, s, std::integral_constant<bool,
2016-10-10 08:28:12 -04:00
isRequest && std::is_member_function_pointer<
decltype(&Derived::on_uri)>::value>{});
}
else
{
ec = parse_error::headers_too_big;
}
2016-04-25 05:27:34 -04:00
}
2016-03-11 06:40:37 -05:00
2016-04-25 05:27:34 -04:00
void call_on_reason(error_code& ec,
boost::string_ref const& s, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_reason<Derived>::value,
"on_reason requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_reason(s, ec);
}
void call_on_reason(error_code&,
boost::string_ref const&, std::false_type)
{
}
void call_on_reason(error_code& ec, boost::string_ref const& s)
{
if(! h_max_ || s.size() <= h_left_)
{
h_left_ -= s.size();
call_on_reason(ec, s, std::integral_constant<bool,
2016-10-10 08:28:12 -04:00
! isRequest && std::is_member_function_pointer<
decltype(&Derived::on_reason)>::value>{});
}
else
{
ec = parse_error::headers_too_big;
}
2016-04-25 05:27:34 -04:00
}
void call_on_request(error_code& ec, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_request<Derived>::value,
"on_request requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_request(ec);
}
void call_on_request(error_code&, std::false_type)
{
}
void call_on_request(error_code& ec)
{
2016-04-27 07:02:51 -04:00
call_on_request(ec, std::integral_constant<bool,
2016-10-10 08:28:12 -04:00
isRequest && std::is_member_function_pointer<
decltype(&Derived::on_request)>::value>{});
2016-04-25 05:27:34 -04:00
}
void call_on_response(error_code& ec, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_response<Derived>::value,
"on_response requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_response(ec);
}
void call_on_response(error_code&, std::false_type)
{
}
void call_on_response(error_code& ec)
{
2016-04-27 07:02:51 -04:00
call_on_response(ec, std::integral_constant<bool,
2016-10-10 08:28:12 -04:00
! isRequest && std::is_member_function_pointer<
decltype(&Derived::on_response)>::value>{});
2016-04-25 05:27:34 -04:00
}
void call_on_field(error_code& ec,
boost::string_ref const& s, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_field<Derived>::value,
"on_field requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_field(s, ec);
}
void call_on_field(error_code&,
boost::string_ref const&, std::false_type)
{
}
void call_on_field(error_code& ec, boost::string_ref const& s)
{
if(! h_max_ || s.size() <= h_left_)
{
h_left_ -= s.size();
2016-10-10 08:28:12 -04:00
call_on_field(ec, s,
std::is_member_function_pointer<
decltype(&Derived::on_field)>{});
}
else
{
ec = parse_error::headers_too_big;
}
2016-04-25 05:27:34 -04:00
}
void call_on_value(error_code& ec,
boost::string_ref const& s, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_value<Derived>::value,
"on_value requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_value(s, ec);
}
void call_on_value(error_code&,
boost::string_ref const&, std::false_type)
{
}
void call_on_value(error_code& ec, boost::string_ref const& s)
{
if(! h_max_ || s.size() <= h_left_)
{
h_left_ -= s.size();
2016-10-10 08:28:12 -04:00
call_on_value(ec, s,
std::is_member_function_pointer<
decltype(&Derived::on_value)>{});
}
else
{
ec = parse_error::headers_too_big;
}
2016-04-25 05:27:34 -04:00
}
2016-10-10 07:55:39 -04:00
body_what
call_on_headers(error_code& ec,
std::uint64_t content_length, std::true_type)
2016-04-25 05:27:34 -04:00
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_headers<Derived>::value,
"on_headers requirements not met");
return impl().on_headers(content_length, ec);
2016-04-25 05:27:34 -04:00
}
2016-10-10 07:55:39 -04:00
body_what
call_on_headers(error_code& ec, std::uint64_t, std::false_type)
2016-04-25 05:27:34 -04:00
{
2016-10-10 07:55:39 -04:00
return body_what::normal;
2016-04-25 05:27:34 -04:00
}
2016-10-10 07:55:39 -04:00
body_what
call_on_headers(error_code& ec)
2016-04-25 05:27:34 -04:00
{
return call_on_headers(ec, content_length_,
2016-10-10 08:28:12 -04:00
std::is_member_function_pointer<
decltype(&Derived::on_headers)>{});
2016-04-25 05:27:34 -04:00
}
void call_on_body(error_code& ec,
boost::string_ref const& s, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_body<Derived>::value,
"on_body requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_body(s, ec);
}
void call_on_body(error_code&,
boost::string_ref const&, std::false_type)
{
}
void call_on_body(error_code& ec, boost::string_ref const& s)
{
if(! b_max_ || s.size() <= b_left_)
{
b_left_ -= s.size();
2016-10-10 08:28:12 -04:00
call_on_body(ec, s,
std::is_member_function_pointer<
decltype(&Derived::on_body)>{});
}
else
{
ec = parse_error::body_too_big;
}
2016-04-25 05:27:34 -04:00
}
void call_on_complete(error_code& ec, std::true_type)
{
2016-10-10 08:28:12 -04:00
static_assert(check_on_complete<Derived>::value,
"on_complete requirements not met");
2016-04-25 05:27:34 -04:00
impl().on_complete(ec);
}
void call_on_complete(error_code&, std::false_type)
{
}
void call_on_complete(error_code& ec)
{
2016-10-10 08:28:12 -04:00
call_on_complete(ec, std::is_member_function_pointer<
decltype(&Derived::on_complete)>{});
2016-04-25 05:27:34 -04:00
}
2014-08-26 09:25:19 -07:00
};
} // http
} // beast
#include <beast/http/impl/basic_parser_v1.ipp>
2016-03-11 06:40:37 -05:00
2014-08-26 09:25:19 -07:00
#endif