// // 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_STRING_BODY_HPP #define BEAST_HTTP_STRING_BODY_HPP #include #include #include #include #include #include #include namespace beast { namespace http { /** A Body represented by a std::string. */ struct string_body { using value_type = std::string; class reader { value_type& s_; public: template explicit reader(message& m) noexcept : s_(m.body) { } 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: template explicit writer(message const& msg) : body_(msg.body) { } void init(error_code& ec) { } std::size_t content_length() const { return body_.size(); } template boost::tribool operator()(resume_context&&, error_code&, Write&& write) { write(boost::asio::buffer(body_)); return true; } }; }; } // http } // beast #endif