forked from boostorg/beast
Refactor chunked parsing (API Change):
* parser now has a callback feature for intercepting chunk headers and chunk bodies * The names for basic_parser derived class callbacks have been refactored * basic_parser offers an additional callback for distinguishing chunk body data. Actions Required: * Adjust signatures for required members of user-defined subclasses of basic_parser * Use the new basic_parser chunk callbacks for accessing chunk extensions and chunk bodies.
This commit is contained in:
@@ -14,6 +14,16 @@
|
||||
namespace beast {
|
||||
namespace http {
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
parser<isRequest, Body, Allocator>::
|
||||
~parser()
|
||||
{
|
||||
if(cb_h_)
|
||||
cb_h_->~cb_h_t();
|
||||
if(cb_b_)
|
||||
cb_b_->~cb_b_t();
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
parser<isRequest, Body, Allocator>::
|
||||
parser()
|
||||
@@ -21,6 +31,22 @@ parser()
|
||||
{
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
parser<isRequest, Body, Allocator>::
|
||||
parser(parser&& other)
|
||||
: base_type(std::move(other))
|
||||
, m_(other.m_)
|
||||
, wr_(other.wr_)
|
||||
, wr_inited_(other.wr_inited_)
|
||||
{
|
||||
if(other.cb_h_)
|
||||
cb_h_ = other.cb_h_->move(
|
||||
&cb_h_buf_);
|
||||
if(other.cb_b_)
|
||||
cb_b_ = other.cb_h_->move(
|
||||
&cb_b_buf_);
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
template<class Arg1, class... ArgN, class>
|
||||
parser<isRequest, Body, Allocator>::
|
||||
@@ -34,17 +60,53 @@ parser(Arg1&& arg1, ArgN&&... argn)
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
template<class OtherBody, class... Args, class>
|
||||
parser<isRequest, Body, Allocator>::
|
||||
parser(parser<isRequest, OtherBody, Allocator>&& p,
|
||||
parser(parser<isRequest, OtherBody, Allocator>&& other,
|
||||
Args&&... args)
|
||||
: base_type(std::move(p))
|
||||
, m_(p.release(), std::forward<Args>(args)...)
|
||||
: base_type(std::move(other))
|
||||
, m_(other.release(), std::forward<Args>(args)...)
|
||||
, wr_(m_)
|
||||
{
|
||||
if(wr_inited_)
|
||||
if(other.wr_inited_)
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
||||
"moved-from parser has a body"});
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
template<class Callback>
|
||||
void
|
||||
parser<isRequest, Body, Allocator>::
|
||||
on_chunk_header(Callback& cb)
|
||||
{
|
||||
// Callback may not be constant, caller is responsible for
|
||||
// managing the lifetime of the callback. Copies are not made.
|
||||
BOOST_STATIC_ASSERT(! std::is_const<Callback>::value);
|
||||
|
||||
// Can't set the callback after receiving any chunk data!
|
||||
BOOST_ASSERT(! wr_inited_);
|
||||
|
||||
if(cb_h_)
|
||||
cb_h_->~cb_h_t();
|
||||
cb_h_ = new(&cb_h_buf_) cb_h_t_impl<Callback>(cb);
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Allocator>
|
||||
template<class Callback>
|
||||
void
|
||||
parser<isRequest, Body, Allocator>::
|
||||
on_chunk_body(Callback& cb)
|
||||
{
|
||||
// Callback may not be constant, caller is responsible for
|
||||
// managing the lifetime of the callback. Copies are not made.
|
||||
BOOST_STATIC_ASSERT(! std::is_const<Callback>::value);
|
||||
|
||||
// Can't set the callback after receiving any chunk data!
|
||||
BOOST_ASSERT(! wr_inited_);
|
||||
|
||||
if(cb_b_)
|
||||
cb_b_->~cb_b_t();
|
||||
cb_b_ = new(&cb_b_buf_) cb_b_t_impl<Callback>(cb);
|
||||
}
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
|
||||
|
||||
Reference in New Issue
Block a user