2016-05-28 09:23:54 -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)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef BEAST_HTTP_BASIC_DYNABUF_BODY_HPP
|
|
|
|
|
#define BEAST_HTTP_BASIC_DYNABUF_BODY_HPP
|
|
|
|
|
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <beast/core/error.hpp>
|
|
|
|
|
#include <beast/http/message.hpp>
|
|
|
|
|
#include <beast/http/resume_context.hpp>
|
2016-10-13 12:32:01 +10:00
|
|
|
#include <beast/core/detail/type_traits.hpp>
|
2016-05-28 09:23:54 -04:00
|
|
|
#include <boost/asio/buffer.hpp>
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <boost/logic/tribool.hpp>
|
2016-05-28 09:23:54 -04:00
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
|
|
/** A message body represented by a @b `DynamicBuffer`
|
|
|
|
|
|
|
|
|
|
Meets the requirements of @b `Body`.
|
|
|
|
|
*/
|
|
|
|
|
template<class DynamicBuffer>
|
|
|
|
|
struct basic_dynabuf_body
|
|
|
|
|
{
|
|
|
|
|
/// The type of the `message::body` member
|
|
|
|
|
using value_type = DynamicBuffer;
|
|
|
|
|
|
|
|
|
|
#if GENERATING_DOCS
|
|
|
|
|
private:
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
class reader
|
|
|
|
|
{
|
|
|
|
|
value_type& sb_;
|
|
|
|
|
|
|
|
|
|
public:
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Fields>
|
2016-05-28 09:23:54 -04:00
|
|
|
explicit
|
|
|
|
|
reader(message<isRequest,
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_dynabuf_body, Fields>& m) noexcept
|
2016-05-28 09:23:54 -04:00
|
|
|
: sb_(m.body)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 09:29:14 -04:00
|
|
|
void
|
|
|
|
|
init(error_code&) noexcept
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-28 09:23:54 -04:00
|
|
|
void
|
|
|
|
|
write(void const* data,
|
|
|
|
|
std::size_t size, error_code&) noexcept
|
|
|
|
|
{
|
|
|
|
|
using boost::asio::buffer;
|
|
|
|
|
using boost::asio::buffer_copy;
|
|
|
|
|
sb_.commit(buffer_copy(
|
|
|
|
|
sb_.prepare(size), buffer(data, size)));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class writer
|
|
|
|
|
{
|
|
|
|
|
DynamicBuffer const& body_;
|
|
|
|
|
|
|
|
|
|
public:
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Fields>
|
2016-05-28 09:23:54 -04:00
|
|
|
explicit
|
|
|
|
|
writer(message<
|
2016-11-10 05:34:49 -05:00
|
|
|
isRequest, basic_dynabuf_body, Fields> const& m) noexcept
|
2016-05-28 09:23:54 -04:00
|
|
|
: body_(m.body)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-10-15 13:40:17 -04:00
|
|
|
init(error_code& ec) noexcept
|
2016-05-28 09:23:54 -04:00
|
|
|
{
|
2016-10-13 12:32:01 +10:00
|
|
|
beast::detail::ignore_unused(ec);
|
2016-05-28 09:23:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::uint64_t
|
2016-10-15 13:40:17 -04:00
|
|
|
content_length() const noexcept
|
2016-05-28 09:23:54 -04:00
|
|
|
{
|
|
|
|
|
return body_.size();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 13:40:17 -04:00
|
|
|
template<class WriteFunction>
|
2016-05-28 09:23:54 -04:00
|
|
|
boost::tribool
|
2016-10-15 13:40:17 -04:00
|
|
|
write(resume_context&&, error_code&,
|
|
|
|
|
WriteFunction&& wf) noexcept
|
2016-05-28 09:23:54 -04:00
|
|
|
{
|
2016-10-15 13:40:17 -04:00
|
|
|
wf(body_.data());
|
2016-05-28 09:23:54 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|