2016-11-20 07:32:41 -05:00
|
|
|
//
|
|
|
|
|
// Copyright (c) 2013-2017 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)
|
|
|
|
|
//
|
|
|
|
|
|
2017-06-03 08:40:53 -07:00
|
|
|
#ifndef BEAST_HTTP_IMPL_PARSER_IPP
|
|
|
|
|
#define BEAST_HTTP_IMPL_PARSER_IPP
|
2016-11-20 07:32:41 -05:00
|
|
|
|
2017-06-05 06:44:31 -07:00
|
|
|
#include <boost/throw_exception.hpp>
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
2016-11-20 07:32:41 -05:00
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2017-07-12 18:06:36 -07:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 20:08:52 -07:00
|
|
|
template<bool isRequest, class Body, class Allocator>
|
|
|
|
|
parser<isRequest, Body, Allocator>::
|
|
|
|
|
parser()
|
|
|
|
|
: wr_(m_)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 18:06:36 -07:00
|
|
|
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_);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 11:54:53 -07:00
|
|
|
template<bool isRequest, class Body, class Allocator>
|
2016-11-20 07:32:41 -05:00
|
|
|
template<class Arg1, class... ArgN, class>
|
2017-06-19 11:54:53 -07:00
|
|
|
parser<isRequest, Body, Allocator>::
|
2017-06-03 08:56:21 -07:00
|
|
|
parser(Arg1&& arg1, ArgN&&... argn)
|
2016-11-20 07:32:41 -05:00
|
|
|
: m_(std::forward<Arg1>(arg1),
|
|
|
|
|
std::forward<ArgN>(argn)...)
|
2017-07-07 20:08:52 -07:00
|
|
|
, wr_(m_)
|
2016-11-20 07:32:41 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 11:54:53 -07:00
|
|
|
template<bool isRequest, class Body, class Allocator>
|
2017-06-05 07:20:58 -07:00
|
|
|
template<class OtherBody, class... Args, class>
|
2017-06-19 11:54:53 -07:00
|
|
|
parser<isRequest, Body, Allocator>::
|
2017-07-12 18:06:36 -07:00
|
|
|
parser(parser<isRequest, OtherBody, Allocator>&& other,
|
2017-06-05 06:44:31 -07:00
|
|
|
Args&&... args)
|
2017-07-12 18:06:36 -07:00
|
|
|
: base_type(std::move(other))
|
|
|
|
|
, m_(other.release(), std::forward<Args>(args)...)
|
2017-07-07 20:08:52 -07:00
|
|
|
, wr_(m_)
|
2017-06-05 06:44:31 -07:00
|
|
|
{
|
2017-07-12 18:06:36 -07:00
|
|
|
if(other.wr_inited_)
|
2017-06-05 06:44:31 -07:00
|
|
|
BOOST_THROW_EXCEPTION(std::invalid_argument{
|
|
|
|
|
"moved-from parser has a body"});
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 18:06:36 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:32:41 -05:00
|
|
|
} // http
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|