2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BEAST_HTTP_STRING_BODY_HPP
9 #define BEAST_HTTP_STRING_BODY_HPP
11 #include <beast/config.hpp>
12 #include <beast/core/error.hpp>
13 #include <beast/http/message.hpp>
14 #include <beast/core/detail/type_traits.hpp>
15 #include <boost/asio/buffer.hpp>
22 /** A Body represented by a std::string.
24 Meets the requirements of @b `Body`.
28 /// The type of the `message::body` member
29 using value_type = std::string;
41 static bool constexpr is_direct = true;
43 using mutable_buffers_type =
44 boost::asio::mutable_buffers_1;
46 template<bool isRequest, class Fields>
48 reader(message<isRequest,
49 string_body, Fields>& m)
60 init(std::uint64_t content_length)
63 (std::numeric_limits<std::size_t>::max)())
64 throw std::length_error{
65 "Content-Length overflow"};
66 body_.reserve(static_cast<
67 std::size_t>(content_length));
71 prepare(std::size_t n)
73 body_.resize(len_ + n);
74 return {&body_[len_], n};
80 if(body_.size() > len_ + n)
81 body_.resize(len_ + n);
94 value_type const& body_;
97 template<bool isRequest, class Fields>
100 isRequest, string_body, Fields> const& msg) noexcept
106 init(error_code& ec) noexcept
108 beast::detail::ignore_unused(ec);
112 content_length() const noexcept
117 template<class WriteFunction>
119 write(error_code&, WriteFunction&& wf) noexcept
121 wf(boost::asio::buffer(body_));