diff --git a/CHANGELOG.md b/CHANGELOG.md index e88dcd86..32d5bfa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +Version 116: + +API Changes: + +* message::body is a member function + +Actions Required: + +* Call member function message::body instead of accessing + the data member at call sites. + +-------------------------------------------------------------------------------- + Version 115: * Update README.md master doc link diff --git a/example/advanced/server-flex/advanced_server_flex.cpp b/example/advanced/server-flex/advanced_server_flex.cpp index 698ce54a..86b4e0d6 100644 --- a/example/advanced/server-flex/advanced_server_flex.cpp +++ b/example/advanced/server-flex/advanced_server_flex.cpp @@ -124,7 +124,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -137,7 +137,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -150,7 +150,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/advanced/server/advanced_server.cpp b/example/advanced/server/advanced_server.cpp index fb1926a4..186d1de2 100644 --- a/example/advanced/server/advanced_server.cpp +++ b/example/advanced/server/advanced_server.cpp @@ -118,7 +118,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -131,7 +131,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -144,7 +144,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/doc/http_examples.hpp b/example/doc/http_examples.hpp index 00f838f6..3c33f373 100644 --- a/example/doc/http_examples.hpp +++ b/example/doc/http_examples.hpp @@ -210,8 +210,8 @@ send_cgi_response( // that it might be coming later. Otherwise the // serializer::is_done would return true right after // sending the header. - res.body.data = nullptr; - res.body.more = true; + res.body().data = nullptr; + res.body().more = true; // Create the serializer. response_serializer sr{res}; @@ -235,10 +235,10 @@ send_cgi_response( ec = {}; // `nullptr` indicates there is no buffer - res.body.data = nullptr; + res.body().data = nullptr; // `false` means no more data is coming - res.body.more = false; + res.body().more = false; } else { @@ -248,9 +248,9 @@ send_cgi_response( // Point to our buffer with the bytes that // we received, and indicate that there may // be some more data coming - res.body.data = buffer; - res.body.size = bytes_transferred; - res.body.more = true; + res.body().data = buffer; + res.body().size = bytes_transferred; + res.body().more = true; } // Write everything in the body buffer @@ -328,7 +328,7 @@ void do_server_head( // We deliver the same payload for GET requests // regardless of the target. A real server might // deliver a file based on the target. - res.body = payload; + res.body() = payload; } break; } @@ -339,7 +339,7 @@ void do_server_head( // we do not recognize the request method. res.result(status::bad_request); res.set(field::content_type, "text/plain"); - res.body = "Invalid request-method '" + req.method_string().to_string() + "'"; + res.body() = "Invalid request-method '" + req.method_string().to_string() + "'"; res.prepare_payload(); break; } @@ -520,8 +520,8 @@ relay( if(! p.is_done()) { // Set up the body for writing into our small buffer - p.get().body.data = buf; - p.get().body.size = sizeof(buf); + p.get().body().data = buf; + p.get().body().size = sizeof(buf); // Read as much as we can read(input, buffer, p, ec); @@ -534,14 +534,14 @@ relay( // Set up the body for reading. // This is how much was parsed: - p.get().body.size = sizeof(buf) - p.get().body.size; - p.get().body.data = buf; - p.get().body.more = ! p.is_done(); + p.get().body().size = sizeof(buf) - p.get().body().size; + p.get().body().data = buf; + p.get().body().more = ! p.is_done(); } else { - p.get().body.data = nullptr; - p.get().body.size = 0; + p.get().body().data = nullptr; + p.get().body().size = 0; } // Write everything in the buffer (which might be empty) @@ -1095,14 +1095,14 @@ read_and_print_body( while(! p.is_done()) { char buf[512]; - p.get().body.data = buf; - p.get().body.size = sizeof(buf); + p.get().body().data = buf; + p.get().body().size = sizeof(buf); read(stream, buffer, p, ec); if(ec == error::need_buffer) ec.assign(0, ec.category()); if(ec) return; - os.write(buf, sizeof(buf) - p.get().body.size); + os.write(buf, sizeof(buf) - p.get().body().size); } } diff --git a/example/http/server/async-ssl/http_server_async_ssl.cpp b/example/http/server/async-ssl/http_server_async_ssl.cpp index 4dff6ed4..d0c4168d 100644 --- a/example/http/server/async-ssl/http_server_async_ssl.cpp +++ b/example/http/server/async-ssl/http_server_async_ssl.cpp @@ -119,7 +119,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -132,7 +132,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -145,7 +145,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/async/http_server_async.cpp b/example/http/server/async/http_server_async.cpp index 5c3f96e6..297be65a 100644 --- a/example/http/server/async/http_server_async.cpp +++ b/example/http/server/async/http_server_async.cpp @@ -115,7 +115,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -128,7 +128,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -141,7 +141,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/coro-ssl/http_server_coro_ssl.cpp b/example/http/server/coro-ssl/http_server_coro_ssl.cpp index 592a1fde..df7ab677 100644 --- a/example/http/server/coro-ssl/http_server_coro_ssl.cpp +++ b/example/http/server/coro-ssl/http_server_coro_ssl.cpp @@ -118,7 +118,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -131,7 +131,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -144,7 +144,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/coro/http_server_coro.cpp b/example/http/server/coro/http_server_coro.cpp index 2a9e63ed..2e42cf86 100644 --- a/example/http/server/coro/http_server_coro.cpp +++ b/example/http/server/coro/http_server_coro.cpp @@ -114,7 +114,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -127,7 +127,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -140,7 +140,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/fast/http_server_fast.cpp b/example/http/server/fast/http_server_fast.cpp index e470c508..06be184d 100644 --- a/example/http/server/fast/http_server_fast.cpp +++ b/example/http/server/fast/http_server_fast.cpp @@ -212,7 +212,7 @@ private: string_response_->set(http::field::server, "Beast"); string_response_->set(http::field::connection, "close"); string_response_->set(http::field::content_type, "text/plain"); - string_response_->body = error; + string_response_->body() = error; string_response_->prepare_payload(); string_serializer_.emplace(*string_response_); @@ -268,7 +268,7 @@ private: file_response_->set(http::field::server, "Beast"); file_response_->set(http::field::connection, "close"); file_response_->set(http::field::content_type, mime_type(target.to_string())); - file_response_->body = std::move(file); + file_response_->body() = std::move(file); file_response_->prepare_payload(); file_serializer_.emplace(*file_response_); diff --git a/example/http/server/flex/http_server_flex.cpp b/example/http/server/flex/http_server_flex.cpp index 85749ad5..2bb538de 100644 --- a/example/http/server/flex/http_server_flex.cpp +++ b/example/http/server/flex/http_server_flex.cpp @@ -119,7 +119,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -132,7 +132,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -145,7 +145,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/small/http_server_small.cpp b/example/http/server/small/http_server_small.cpp index 8ed8d422..1f26484e 100644 --- a/example/http/server/small/http_server_small.cpp +++ b/example/http/server/small/http_server_small.cpp @@ -116,7 +116,7 @@ private: // we do not recognize the request method. response_.result(http::status::bad_request); response_.set(http::field::content_type, "text/plain"); - boost::beast::ostream(response_.body) + boost::beast::ostream(response_.body()) << "Invalid request-method '" << request_.method_string().to_string() << "'"; @@ -133,7 +133,7 @@ private: if(request_.target() == "/count") { response_.set(http::field::content_type, "text/html"); - boost::beast::ostream(response_.body) + boost::beast::ostream(response_.body()) << "\n" << "Request count\n" << "\n" @@ -147,7 +147,7 @@ private: else if(request_.target() == "/time") { response_.set(http::field::content_type, "text/html"); - boost::beast::ostream(response_.body) + boost::beast::ostream(response_.body()) << "\n" << "Current time\n" << "\n" @@ -162,7 +162,7 @@ private: { response_.result(http::status::not_found); response_.set(http::field::content_type, "text/plain"); - boost::beast::ostream(response_.body) << "File not found\r\n"; + boost::beast::ostream(response_.body()) << "File not found\r\n"; } } @@ -172,7 +172,7 @@ private: { auto self = shared_from_this(); - response_.set(http::field::content_length, response_.body.size()); + response_.set(http::field::content_length, response_.body().size()); http::async_write( socket_, diff --git a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp index c7386e4b..9d0352af 100644 --- a/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp +++ b/example/http/server/stackless-ssl/http_server_stackless_ssl.cpp @@ -120,7 +120,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -133,7 +133,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -146,7 +146,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/stackless/http_server_stackless.cpp b/example/http/server/stackless/http_server_stackless.cpp index 4db45ab2..50af6c35 100644 --- a/example/http/server/stackless/http_server_stackless.cpp +++ b/example/http/server/stackless/http_server_stackless.cpp @@ -116,7 +116,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -129,7 +129,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -142,7 +142,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/sync-ssl/http_server_sync_ssl.cpp b/example/http/server/sync-ssl/http_server_sync_ssl.cpp index d6c7c34e..87901c92 100644 --- a/example/http/server/sync-ssl/http_server_sync_ssl.cpp +++ b/example/http/server/sync-ssl/http_server_sync_ssl.cpp @@ -115,7 +115,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -128,7 +128,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -141,7 +141,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/example/http/server/sync/http_server_sync.cpp b/example/http/server/sync/http_server_sync.cpp index 0a813448..1aaf3162 100644 --- a/example/http/server/sync/http_server_sync.cpp +++ b/example/http/server/sync/http_server_sync.cpp @@ -113,7 +113,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = why.to_string(); + res.body() = why.to_string(); res.prepare_payload(); return res; }; @@ -126,7 +126,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "The resource '" + target.to_string() + "' was not found."; + res.body() = "The resource '" + target.to_string() + "' was not found."; res.prepare_payload(); return res; }; @@ -139,7 +139,7 @@ handle_request( res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::content_type, "text/html"); res.keep_alive(req.keep_alive()); - res.body = "An error occurred: '" + what.to_string() + "'"; + res.body() = "An error occurred: '" + what.to_string() + "'"; res.prepare_payload(); return res; }; diff --git a/include/boost/beast/core/detail/empty_base_optimization.hpp b/include/boost/beast/core/detail/empty_base_optimization.hpp index f2e6dace..b1e728b6 100644 --- a/include/boost/beast/core/detail/empty_base_optimization.hpp +++ b/include/boost/beast/core/detail/empty_base_optimization.hpp @@ -19,31 +19,32 @@ namespace beast { namespace detail { template -struct empty_base_optimization_decide +struct is_empty_base_optimization_derived : std::integral_constant::value && ! boost::is_final::value> { }; -template< - class T, - int UniqueID = 0, - bool ShouldDeriveFrom = - empty_base_optimization_decide::value -> +template::value> class empty_base_optimization : private T { public: empty_base_optimization() = default; + empty_base_optimization(empty_base_optimization&&) = default; + empty_base_optimization(empty_base_optimization const&) = default; + empty_base_optimization& operator=(empty_base_optimization&&) = default; + empty_base_optimization& operator=(empty_base_optimization const&) = default; - empty_base_optimization(T const& t) - : T (t) - {} - - empty_base_optimization(T&& t) - : T (std::move (t)) - {} + template + explicit + empty_base_optimization(Arg1&& arg1, ArgN&&... argn) + : T(std::forward(arg1), + std::forward(argn)...) + { + } T& member() noexcept { @@ -64,29 +65,32 @@ template< > class empty_base_optimization { + T t_; + public: empty_base_optimization() = default; + empty_base_optimization(empty_base_optimization&&) = default; + empty_base_optimization(empty_base_optimization const&) = default; + empty_base_optimization& operator=(empty_base_optimization&&) = default; + empty_base_optimization& operator=(empty_base_optimization const&) = default; - empty_base_optimization(T const& t) - : m_t (t) - {} - - empty_base_optimization(T&& t) - : m_t (std::move (t)) - {} + template + explicit + empty_base_optimization(Arg1&& arg1, ArgN&&... argn) + : t_(std::forward(arg1), + std::forward(argn)...) + { + } T& member() noexcept { - return m_t; + return t_; } T const& member() const noexcept { - return m_t; + return t_; } - -private: - T m_t; }; } // detail diff --git a/include/boost/beast/http/basic_dynamic_body.hpp b/include/boost/beast/http/basic_dynamic_body.hpp index f6fde1c0..416f4239 100644 --- a/include/boost/beast/http/basic_dynamic_body.hpp +++ b/include/boost/beast/http/basic_dynamic_body.hpp @@ -74,7 +74,7 @@ struct basic_dynamic_body explicit reader(message const& m) - : body_(m.body) + : body_(m.body()) { } @@ -109,7 +109,7 @@ struct basic_dynamic_body explicit writer(message& msg) - : body_(msg.body) + : body_(msg.body()) { } diff --git a/include/boost/beast/http/basic_file_body.hpp b/include/boost/beast/http/basic_file_body.hpp index c76546fa..c6b25044 100644 --- a/include/boost/beast/http/basic_file_body.hpp +++ b/include/boost/beast/http/basic_file_body.hpp @@ -291,7 +291,7 @@ template basic_file_body:: reader:: reader(message& m) - : body_(m.body) + : body_(m.body()) { // The file must already be open BOOST_ASSERT(body_.file_.is_open()); @@ -442,7 +442,7 @@ template basic_file_body:: writer:: writer(message& m) - : body_(m.body) + : body_(m.body()) { } diff --git a/include/boost/beast/http/buffer_body.hpp b/include/boost/beast/http/buffer_body.hpp index 9473d84a..780e63ee 100644 --- a/include/boost/beast/http/buffer_body.hpp +++ b/include/boost/beast/http/buffer_body.hpp @@ -111,7 +111,7 @@ struct buffer_body explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -169,7 +169,7 @@ struct buffer_body template explicit writer(message& m) - : body_(m.body) + : body_(m.body()) { } diff --git a/include/boost/beast/http/impl/file_body_win32.ipp b/include/boost/beast/http/impl/file_body_win32.ipp index c1191538..1ef2472e 100644 --- a/include/boost/beast/http/impl/file_body_win32.ipp +++ b/include/boost/beast/http/impl/file_body_win32.ipp @@ -125,7 +125,7 @@ struct basic_file_body template reader(message, Fields>& m) - : body_(m.body) + : body_(m.body()) { } @@ -168,7 +168,7 @@ struct basic_file_body template explicit writer(message& m) - : body_(m.body) + : body_(m.body()) { } @@ -437,7 +437,7 @@ operator()() ov.OffsetHigh = highPart(r.pos_); auto const bSuccess = ::TransmitFile( sock_.native_handle(), - sr_.get().body.file_.native_handle(), + sr_.get().body().file_.native_handle(), nNumberOfBytesToWrite, 0, overlapped.get(), diff --git a/include/boost/beast/http/impl/message.ipp b/include/boost/beast/http/impl/message.ipp index 93abbafb..fc19ec27 100644 --- a/include/boost/beast/http/impl/message.ipp +++ b/include/boost/beast/http/impl/message.ipp @@ -209,7 +209,9 @@ template message:: message(header_type&& h, BodyArgs&&... body_args) : header_type(std::move(h)) - , body(std::forward(body_args)...) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_args)...) { } @@ -218,7 +220,9 @@ template message:: message(header_type const& h, BodyArgs&&... body_args) : header_type(h) - , body(std::forward(body_args)...) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_args)...) { } @@ -236,7 +240,9 @@ message:: message(verb method, string_view target, Version version, BodyArg&& body_arg) : header_type(method, target, version) - , body(std::forward(body_arg)) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_arg)) { } @@ -249,7 +255,9 @@ message( FieldsArg&& fields_arg) : header_type(method, target, version, std::forward(fields_arg)) - , body(std::forward(body_arg)) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_arg)) { } @@ -267,7 +275,9 @@ message:: message(status result, Version version, BodyArg&& body_arg) : header_type(result, version) - , body(std::forward(body_arg)) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_arg)) { } @@ -278,7 +288,9 @@ message(status result, Version version, BodyArg&& body_arg, FieldsArg&& fields_arg) : header_type(result, version, std::forward(fields_arg)) - , body(std::forward(body_arg)) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward(body_arg)) { } @@ -409,7 +421,7 @@ swap( swap( static_cast&>(m1), static_cast&>(m2)); - swap(m1.body, m2.body); + swap(m1.body(), m2.body()); } } // http diff --git a/include/boost/beast/http/message.hpp b/include/boost/beast/http/message.hpp index adf1fbe9..a2868318 100644 --- a/include/boost/beast/http/message.hpp +++ b/include/boost/beast/http/message.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -391,6 +392,14 @@ using request_header = header; template using response_header = header; +#if defined(BOOST_MSVC) +// Workaround for MSVC bug with private base classes +namespace detail { +template +using value_type_t = typename T::value_type; +} // detail +#endif + /** A container for a complete HTTP message. This container is derived from the `Fields` template type. @@ -421,7 +430,12 @@ using response_header = header; field value pairs. */ template -struct message : header +struct message + : header +#if ! BOOST_BEAST_DOXYGEN + , beast::detail::empty_base_optimization< + typename Body::value_type> +#endif { /// The base class used to hold the header portion of the message. using header_type = header; @@ -432,9 +446,6 @@ struct message : header */ using body_type = Body; - /// A value representing the body. - typename Body::value_type body; - /// Constructor message() = default; @@ -736,7 +747,7 @@ struct message : header @code request req{verb::post, "/"}; req.set(field::user_agent, "Beast"); - req.body = "Hello, world!"; + req.body() = "Hello, world!"; req.prepare_payload(); @endcode */ @@ -746,6 +757,28 @@ struct message : header prepare_payload(typename header_type::is_request{}); } + /// Returns the body +#if BOOST_BEAST_DOXYGEN || ! defined(BOOST_MSVC) + typename body_type::value_type& +#else + detail::value_type_t& +#endif + body() noexcept + { + return this->member(); + } + + /// Returns the body +#if BOOST_BEAST_DOXYGEN || ! defined(BOOST_MSVC) + typename body_type::value_type const& +#else + detail::value_type_t const& +#endif + body() const noexcept + { + return this->member(); + } + private: static_assert(is_body::value, "Body requirements not met"); @@ -757,8 +790,10 @@ private: std::piecewise_construct_t, std::tuple& body_args, beast::detail::index_sequence) - : body(std::forward( - std::get(body_args))...) + : beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward( + std::get(body_args))...) { boost::ignore_unused(body_args); } @@ -776,8 +811,10 @@ private: beast::detail::index_sequence) : header_type(std::forward( std::get(fields_args))...) - , body(std::forward( - std::get(body_args))...) + , beast::detail::empty_base_optimization< + typename Body::value_type>( + std::forward( + std::get(body_args))...) { boost::ignore_unused(body_args); boost::ignore_unused(fields_args); @@ -786,7 +823,7 @@ private: boost::optional payload_size(std::true_type) const { - return Body::size(body); + return Body::size(this->body()); } boost::optional diff --git a/include/boost/beast/http/span_body.hpp b/include/boost/beast/http/span_body.hpp index 9c6f561f..3530179b 100644 --- a/include/boost/beast/http/span_body.hpp +++ b/include/boost/beast/http/span_body.hpp @@ -78,7 +78,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -117,7 +117,7 @@ public: explicit writer(message& m) - : body_(m.body) + : body_(m.body()) { } diff --git a/include/boost/beast/http/string_body.hpp b/include/boost/beast/http/string_body.hpp index cd94243d..25523c9a 100644 --- a/include/boost/beast/http/string_body.hpp +++ b/include/boost/beast/http/string_body.hpp @@ -86,7 +86,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -122,7 +122,7 @@ public: explicit writer(message& m) - : body_(m.body) + : body_(m.body()) { } diff --git a/include/boost/beast/http/vector_body.hpp b/include/boost/beast/http/vector_body.hpp index d9d00b60..e4ab3ea1 100644 --- a/include/boost/beast/http/vector_body.hpp +++ b/include/boost/beast/http/vector_body.hpp @@ -81,7 +81,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -117,7 +117,7 @@ public: explicit writer(message& m) - : body_(m.body) + : body_(m.body()) { } diff --git a/include/boost/beast/websocket/impl/stream.ipp b/include/boost/beast/websocket/impl/stream.ipp index b783a9a5..d02d7710 100644 --- a/include/boost/beast/websocket/impl/stream.ipp +++ b/include/boost/beast/websocket/impl/stream.ipp @@ -577,7 +577,7 @@ build_response(http::request req; req.version = 11; req.method(verb::get); - req.body = 50; + req.body() = 50; req.prepare_payload(); BEAST_EXPECT(req[field::content_length] == "50"); @@ -515,7 +515,7 @@ public: request req; req.version = 11; req.method(verb::put); - req.body = 50; + req.body() = 50; req.prepare_payload(); BEAST_EXPECT(req[field::content_length] == "50"); @@ -580,7 +580,7 @@ public: { response res; res.version = 11; - res.body = 50; + res.body() = 50; res.prepare_payload(); BEAST_EXPECT(res[field::content_length] == "50"); diff --git a/test/beast/http/file_body.cpp b/test/beast/http/file_body.cpp index 838d38e9..b63a5ce7 100644 --- a/test/beast/http/file_body.cpp +++ b/test/beast/http/file_body.cpp @@ -54,7 +54,7 @@ public: response_parser> p; p.eager(true); - p.get().body.open( + p.get().body().open( temp.string().c_str(), file_mode::write, ec); BEAST_EXPECTS(! ec, ec.message()); @@ -78,7 +78,7 @@ public: { response> res{status::ok, 11}; res.set(field::server, "test"); - res.body.open(temp.string().c_str(), + res.body().open(temp.string().c_str(), file_mode::scan, ec); BEAST_EXPECTS(! ec, ec.message()); res.prepare_payload(); diff --git a/test/beast/http/message.cpp b/test/beast/http/message.cpp index 61079c9f..b229552e 100644 --- a/test/beast/http/message.cpp +++ b/test/beast/http/message.cpp @@ -156,17 +156,17 @@ public: request m1; request m2; m1.target("u"); - m1.body = "1"; + m1.body() = "1"; m1.insert("h", "v"); m2.method_string("G"); - m2.body = "2"; + m2.body() = "2"; swap(m1, m2); BEAST_EXPECT(m1.method_string() == "G"); BEAST_EXPECT(m2.method_string().empty()); BEAST_EXPECT(m1.target().empty()); BEAST_EXPECT(m2.target() == "u"); - BEAST_EXPECT(m1.body == "2"); - BEAST_EXPECT(m2.body == "1"); + BEAST_EXPECT(m1.body() == "2"); + BEAST_EXPECT(m2.body() == "1"); BEAST_EXPECT(! m1.count("h")); BEAST_EXPECT(m2.count("h")); } @@ -231,7 +231,7 @@ public: BEAST_EXPECT(req.version == 11); BEAST_EXPECT(req.method() == verb::get); BEAST_EXPECT(req.target() == "/"); - BEAST_EXPECT(req.body == "Hello"); + BEAST_EXPECT(req.body() == "Hello"); } { request req{ @@ -239,7 +239,7 @@ public: BEAST_EXPECT(req.version == 11); BEAST_EXPECT(req.method() == verb::get); BEAST_EXPECT(req.target() == "/"); - BEAST_EXPECT(req.body == "Hello"); + BEAST_EXPECT(req.body() == "Hello"); } { response res; @@ -258,7 +258,7 @@ public: BEAST_EXPECT(res.version == 10); BEAST_EXPECT(res.result() == status::bad_request); BEAST_EXPECT(res.reason() == "Bad Request"); - BEAST_EXPECT(res.body == "Hello"); + BEAST_EXPECT(res.body() == "Hello"); } { response res{ @@ -266,7 +266,7 @@ public: BEAST_EXPECT(res.version == 10); BEAST_EXPECT(res.result() == status::bad_request); BEAST_EXPECT(res.reason() == "Bad Request"); - BEAST_EXPECT(res.body == "Hello"); + BEAST_EXPECT(res.body() == "Hello"); } } @@ -277,10 +277,10 @@ public: response m2; m1.result(status::ok); m1.version = 10; - m1.body = "1"; + m1.body() = "1"; m1.insert("h", "v"); m2.result(status::not_found); - m2.body = "2"; + m2.body() = "2"; m2.version = 11; swap(m1, m2); BEAST_EXPECT(m1.result() == status::not_found); @@ -291,8 +291,8 @@ public: BEAST_EXPECT(m2.reason() == "OK"); BEAST_EXPECT(m1.version == 11); BEAST_EXPECT(m2.version == 10); - BEAST_EXPECT(m1.body == "2"); - BEAST_EXPECT(m2.body == "1"); + BEAST_EXPECT(m1.body() == "2"); + BEAST_EXPECT(m2.body() == "1"); BEAST_EXPECT(! m1.count("h")); BEAST_EXPECT(m2.count("h")); } diff --git a/test/beast/http/parser.cpp b/test/beast/http/parser.cpp index ebc5558a..f618bcc1 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -135,7 +135,7 @@ public: BEAST_EXPECT(m.result() == status::ok); BEAST_EXPECT(m.reason() == "OK"); BEAST_EXPECT(m["Server"] == "test"); - BEAST_EXPECT(m.body == "Hello, world!"); + BEAST_EXPECT(m.body() == "Hello, world!"); } ); doMatrix( @@ -165,7 +165,7 @@ public: BEAST_EXPECT(m["Transfer-Encoding"] == "chunked"); BEAST_EXPECT(m["Expires"] == "never"); BEAST_EXPECT(m["MD5-Fingerprint"] == "-"); - BEAST_EXPECT(m.body == "*****--"); + BEAST_EXPECT(m.body() == "*****--"); } ); doMatrix( @@ -177,7 +177,7 @@ public: [&](parser_type const& p) { auto const& m = p.get(); - BEAST_EXPECT(m.body == "*****"); + BEAST_EXPECT(m.body() == "*****"); } ); doMatrix( @@ -228,7 +228,7 @@ public: BEAST_EXPECT(m.target() == "/"); BEAST_EXPECT(m.version == 11); BEAST_EXPECT(m["User-Agent"] == "test"); - BEAST_EXPECT(m.body == "*"); + BEAST_EXPECT(m.body() == "*"); } { // test partial parsing of final chunk @@ -247,7 +247,7 @@ public: b.consume(used); BEAST_EXPECT(! ec); BEAST_EXPECT(! p.is_done()); - BEAST_EXPECT(p.get().body == "*"); + BEAST_EXPECT(p.get().body() == "*"); ostream(b) << "\r\n" "0;d;e=3;f=\"4\"\r\n" diff --git a/test/beast/http/serializer.cpp b/test/beast/http/serializer.cpp index 171333d4..3d364730 100644 --- a/test/beast/http/serializer.cpp +++ b/test/beast/http/serializer.cpp @@ -102,7 +102,7 @@ public: lambda visit; error_code ec; response res; - res.body.append(1000, '*'); + res.body().append(1000, '*'); serializer sr{res}; sr.limit(limit); for(;;) diff --git a/test/beast/http/span_body.cpp b/test/beast/http/span_body.cpp index e6e9aa13..2dbf2c0f 100644 --- a/test/beast/http/span_body.cpp +++ b/test/beast/http/span_body.cpp @@ -27,12 +27,12 @@ struct span_body_test using B = span_body; request req; - BEAST_EXPECT(req.body.size() == 0); - BEAST_EXPECT(B::size(req.body) == 0); + BEAST_EXPECT(req.body().size() == 0); + BEAST_EXPECT(B::size(req.body()) == 0); - req.body = B::value_type("xyz", 3); - BEAST_EXPECT(req.body.size() == 3); - BEAST_EXPECT(B::size(req.body) == 3); + req.body() = B::value_type("xyz", 3); + BEAST_EXPECT(req.body().size() == 3); + BEAST_EXPECT(B::size(req.body()) == 3); B::reader r{req}; error_code ec; @@ -49,7 +49,7 @@ struct span_body_test char buf[5]; using B = span_body; request req; - req.body = span{buf, sizeof(buf)}; + req.body() = span{buf, sizeof(buf)}; B::writer w{req}; error_code ec; w.init(boost::none, ec); diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index 7d4ccfdc..d4a8fbeb 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -50,7 +50,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -95,7 +95,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -232,7 +232,7 @@ public: explicit reader(message const& msg) - : body_(msg.body) + : body_(msg.body()) { } @@ -292,7 +292,7 @@ public: try { read(ts, b, m); - return m.body == body; + return m.body() == body; } catch(std::exception const& e) { @@ -323,7 +323,7 @@ public: m.result(status::ok); m.set(field::server, "test"); m.set(field::content_length, "5"); - m.body = "*****"; + m.body() = "*****"; error_code ec; test::stream ts{ios_}, tr{ios_}; ts.connect(tr); @@ -342,7 +342,7 @@ public: m.result(status::ok); m.set(field::server, "test"); m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; + m.body() = "*****"; error_code ec; test::stream ts{ios_}, tr{ios_}; ts.connect(tr); @@ -374,7 +374,7 @@ public: m.set(field::user_agent, "test"); m.set(field::connection, "keep-alive"); m.set(field::content_length, "5"); - m.body = "*****"; + m.body() = "*****"; try { write(ts, m); @@ -403,7 +403,7 @@ public: request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; + m.body() = "*****"; error_code ec = test::error::fail_error; write(ts, m, ec); if(ec == error::end_of_stream) @@ -433,7 +433,7 @@ public: request m{verb::get, "/", 10, fc}; m.set(field::user_agent, "test"); m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; + m.body() = "*****"; error_code ec = test::error::fail_error; async_write(ts, m, do_yield[ec]); if(ec == error::end_of_stream) @@ -464,7 +464,7 @@ public: m.set(field::user_agent, "test"); m.set(field::connection, "keep-alive"); m.set(field::content_length, "5"); - m.body = "*****"; + m.body() = "*****"; error_code ec = test::error::fail_error; write(ts, m, ec); if(! ec) @@ -491,7 +491,7 @@ public: m.set(field::user_agent, "test"); m.set(field::connection, "keep-alive"); m.set(field::content_length, "5"); - m.body = "*****"; + m.body() = "*****"; error_code ec = test::error::fail_error; async_write(ts, m, do_yield[ec]); if(! ec) @@ -520,7 +520,7 @@ public: m.target("/"); m.version = 10; m.set(field::user_agent, "test"); - m.body = "*"; + m.body() = "*"; m.prepare_payload(); BEAST_EXPECT(str(m) == "GET / HTTP/1.0\r\n" @@ -537,7 +537,7 @@ public: m.target("/"); m.version = 10; m.set(field::user_agent, "test"); - m.body = "*"; + m.body() = "*"; m.prepare_payload(); test::stream ts{ios_}, tr{ios_}; ts.connect(tr); @@ -558,7 +558,7 @@ public: m.target("/"); m.version = 11; m.set(field::user_agent, "test"); - m.body = "*"; + m.body() = "*"; m.prepare_payload(); BEAST_EXPECT(str(m) == "GET / HTTP/1.1\r\n" @@ -575,7 +575,7 @@ public: m.target("/"); m.version = 11; m.set(field::user_agent, "test"); - m.body = "*"; + m.body() = "*"; m.prepare_payload(); test::stream ts{ios_}, tr{ios_}; ts.connect(tr); @@ -601,7 +601,7 @@ public: m.target("/"); m.version = 11; m.set(field::user_agent, "test"); - m.body = "*"; + m.body() = "*"; BEAST_EXPECT(to_string(m) == "GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*"); } @@ -631,7 +631,7 @@ public: m.version = 11; m.target("/"); m.set("Content-Length", 5); - m.body = "*****"; + m.body() = "*****"; async_write(ts, m, handler{}); BEAST_EXPECT(handler::count() > 0); ios.stop(); @@ -654,7 +654,7 @@ public: m.version = 11; m.target("/"); m.set("Content-Length", 5); - m.body = "*****"; + m.body() = "*****"; async_write(ts, m, handler{}); BEAST_EXPECT(handler::count() > 0); } @@ -716,7 +716,7 @@ public: m0.result(status::ok); m0.reason("OK"); m0.set(field::server, "test"); - m0.body.s = "Hello, world!\n"; + m0.body().s = "Hello, world!\n"; { std::string const result = @@ -730,7 +730,7 @@ public: do_write(ts, m, ec); BEAST_EXPECT(tr.str() == result); BEAST_EXPECT(equal_body( - tr.str(), m.body.s)); + tr.str(), m.body().s)); tr.clear(); } { @@ -739,7 +739,7 @@ public: do_async_write(ts, m, ec, yield); BEAST_EXPECT(tr.str() == result); BEAST_EXPECT(equal_body( - tr.str(), m.body.s)); + tr.str(), m.body().s)); tr.clear(); } { @@ -753,7 +753,7 @@ public: if(sr.is_header_done()) break; } - BEAST_EXPECT(! m.body.read); + BEAST_EXPECT(! m.body().read); tr.clear(); } { @@ -767,7 +767,7 @@ public: if(sr.is_header_done()) break; } - BEAST_EXPECT(! m.body.read); + BEAST_EXPECT(! m.body().read); tr.clear(); } } @@ -778,7 +778,7 @@ public: error_code ec; do_write(ts, m, ec); BEAST_EXPECT(equal_body( - tr.str(), m.body.s)); + tr.str(), m.body().s)); tr.clear(); } { @@ -786,7 +786,7 @@ public: error_code ec; do_async_write(ts, m, ec, yield); BEAST_EXPECT(equal_body( - tr.str(), m.body.s)); + tr.str(), m.body().s)); tr.clear(); } { @@ -800,7 +800,7 @@ public: if(sr.is_header_done()) break; } - BEAST_EXPECT(! m.body.read); + BEAST_EXPECT(! m.body().read); tr.clear(); } { @@ -814,7 +814,7 @@ public: if(sr.is_header_done()) break; } - BEAST_EXPECT(! m.body.read); + BEAST_EXPECT(! m.body().read); tr.clear(); } } diff --git a/test/doc/http_examples.cpp b/test/doc/http_examples.cpp index dfafefd3..7b82e493 100644 --- a/test/doc/http_examples.cpp +++ b/test/doc/http_examples.cpp @@ -78,7 +78,7 @@ public: try { read(ts, b, m); - return m.body == body; + return m.body() == body; } catch(std::exception const& e) { @@ -109,7 +109,7 @@ public: req.method_string("POST"); req.target("/"); req.insert(field::user_agent, "test"); - req.body = "Hello, world!"; + req.body() = "Hello, world!"; req.prepare_payload(); error_code ec; @@ -142,7 +142,7 @@ public: req.method_string("POST"); req.target("/"); req.insert(field::user_agent, "test"); - req.body = "Hello, world!"; + req.body() = "Hello, world!"; req.prepare_payload(); test::stream ds{ios_}, dsr{ios_}; @@ -167,7 +167,7 @@ public: }); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(equal_body( - usr.str(), req.body)); + usr.str(), req.body())); } void @@ -273,7 +273,7 @@ public: void operator()(request&& req) { - body = req.body; + body = req.body(); } }; diff --git a/test/doc/http_snippets.cpp b/test/doc/http_snippets.cpp index a4e9397f..781765fc 100644 --- a/test/doc/http_snippets.cpp +++ b/test/doc/http_snippets.cpp @@ -61,7 +61,7 @@ void fxx() { res.version = 11; // HTTP/1.1 res.result(status::ok); res.set(field::server, "Beast"); - res.body = "Hello, world!"; + res.body() = "Hello, world!"; res.prepare_payload(); //] @@ -115,7 +115,7 @@ void fxx() { res.version = 11; res.result(status::ok); res.set(field::server, "Beast"); - res.body = "Hello, world!"; + res.body() = "Hello, world!"; error_code ec; write(sock, res, ec);