2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
// 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_STRING_BODY_HPP
|
|
|
|
#define BEAST_HTTP_STRING_BODY_HPP
|
|
|
|
|
2017-04-10 19:24:27 -07:00
|
|
|
#include <beast/config.hpp>
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <beast/core/error.hpp>
|
|
|
|
#include <beast/http/message.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>
|
2017-07-20 08:01:46 -07:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
/** A Body represented by a std::string.
|
2016-05-01 12:33:35 -04:00
|
|
|
|
|
|
|
Meets the requirements of @b `Body`.
|
2017-07-20 08:01:46 -07:00
|
|
|
*/
|
|
|
|
struct string_body
|
|
|
|
{
|
|
|
|
/// The type of the `message::body` member
|
|
|
|
using value_type = std::string;
|
|
|
|
|
|
|
|
#if GENERATING_DOCS
|
|
|
|
private:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class reader
|
|
|
|
{
|
|
|
|
value_type& s_;
|
|
|
|
|
|
|
|
public:
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Fields>
|
2017-07-20 08:01:46 -07:00
|
|
|
explicit
|
|
|
|
reader(message<isRequest,
|
2016-11-10 05:34:49 -05:00
|
|
|
string_body, Fields>& m) noexcept
|
2017-07-20 08:01:46 -07:00
|
|
|
: s_(m.body)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-15 09:29:14 -04:00
|
|
|
void
|
|
|
|
init(error_code&) noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
void
|
|
|
|
write(void const* data,
|
|
|
|
std::size_t size, error_code&) noexcept
|
|
|
|
{
|
|
|
|
auto const n = s_.size();
|
|
|
|
s_.resize(n + size);
|
|
|
|
std::memcpy(&s_[n], data, size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class writer
|
|
|
|
{
|
|
|
|
value_type const& body_;
|
|
|
|
|
|
|
|
public:
|
2016-11-10 05:34:49 -05:00
|
|
|
template<bool isRequest, class Fields>
|
2017-07-20 08:01:46 -07:00
|
|
|
explicit
|
2016-05-01 11:14:10 -04:00
|
|
|
writer(message<
|
2016-11-10 05:34:49 -05:00
|
|
|
isRequest, string_body, Fields> const& msg) noexcept
|
2017-07-20 08:01:46 -07:00
|
|
|
: body_(msg.body)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-15 13:40:17 -04:00
|
|
|
init(error_code& ec) noexcept
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-10-13 12:32:01 +10:00
|
|
|
beast::detail::ignore_unused(ec);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
2016-04-29 06:04:40 -04:00
|
|
|
std::uint64_t
|
2016-10-15 13:40:17 -04:00
|
|
|
content_length() const noexcept
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
return body_.size();
|
|
|
|
}
|
|
|
|
|
2016-10-15 13:40:17 -04:00
|
|
|
template<class WriteFunction>
|
2017-03-31 11:15:27 -04:00
|
|
|
bool
|
|
|
|
write(error_code&, WriteFunction&& wf) noexcept
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-10-15 13:40:17 -04:00
|
|
|
wf(boost::asio::buffer(body_));
|
2017-07-20 08:01:46 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // http
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
#endif
|