Files
boost_beast/include/beast/http/basic_dynabuf_body.hpp
T
Vinnie Falco e8be3fd7d3 New HTTP interfaces (API Change):
fix #123
fix #154
fix #265

This completely replaces the HTTP parser used to read and
parse incoming messages. The new version is faster than
the old one, and written in fewer lines. A summary of
changes:

* parse and async_parse renamed to read and async_read

* basic_parser is optimized for linear buffers,
  use flat_streambuf for the best performance with these
  functions:

  - http::read
  - http::read_some
  - http::async_read
  - http::async_read_some

* The overloads of read() and async_read() which take
  just a header have been removed, since they would
  throw away important parse metadata.

* The derived class callbacks for basic_parser have
  been streamlined. All strings passed to callbacks
  are presented in their entirety, instead of being
  provided in pieces.

These changes allow use-cases that were previously
difficult or impossible, such as:

- Efficient relaying

- Late body type commitment

- Expect: 100-continue handling
2017-07-20 08:12:15 -07:00

119 lines
2.3 KiB
C++

//
// 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)
//
#ifndef BEAST_HTTP_BASIC_DYNABUF_BODY_HPP
#define BEAST_HTTP_BASIC_DYNABUF_BODY_HPP
#include <beast/config.hpp>
#include <beast/core/error.hpp>
#include <beast/http/message.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp>
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 BEAST_DOXYGEN
private:
#endif
class reader
{
value_type& body_;
public:
static bool constexpr is_direct = true;
using mutable_buffers_type =
typename DynamicBuffer::mutable_buffers_type;
template<bool isRequest, class Fields>
explicit
reader(message<isRequest,
basic_dynabuf_body, Fields>& msg)
: body_(msg.body)
{
}
void
init()
{
}
void
init(std::uint64_t content_length)
{
}
mutable_buffers_type
prepare(std::size_t n)
{
return body_.prepare(n);
}
void
commit(std::size_t n)
{
body_.commit(n);
}
void
finish()
{
}
};
class writer
{
DynamicBuffer const& body_;
public:
template<bool isRequest, class Fields>
explicit
writer(message<
isRequest, basic_dynabuf_body, Fields> const& m) noexcept
: body_(m.body)
{
}
void
init(error_code& ec) noexcept
{
beast::detail::ignore_unused(ec);
}
std::uint64_t
content_length() const noexcept
{
return body_.size();
}
template<class WriteFunction>
bool
write(error_code&, WriteFunction&& wf) noexcept
{
wf(body_.data());
return true;
}
};
};
} // http
} // beast
#endif