New BodyReader and BodyWriter constructors (API Change):

fix #884

* BodyReader and BodyWriter constructors now require the header and
  body elements to be passed as distinct header and value_type objects.

This enables the composition of body types, for example:

    http::response<compressed_body<http::string_body>> res;

* The previous single-argument constructors are deprecated and will be
  removed in a subsequent version.

Actions Required:

* Change user-defined instances of BodyReader or BodyWriter constructor
  signatures to the two-argument form.

OR

* Define the macro BOOST_BEAST_ALLOW_DEPRECATED in the project (which
  will accept both the new and the deprecated signatures).
This commit is contained in:
Damian Jarek
2017-12-15 09:27:39 -08:00
committed by Vinnie Falco
parent d796319476
commit b76ab4450a
24 changed files with 358 additions and 107 deletions
+46 -2
View File
@@ -20,6 +20,40 @@ namespace http {
class serializer_test : public beast::unit_test::suite
{
public:
struct deprecated_body
{
using value_type = std::string;
class writer
{
public:
using const_buffers_type =
boost::asio::const_buffer;
value_type const& body_;
template<bool isRequest, class Fields>
explicit
writer(message<isRequest, deprecated_body, Fields> const& m):
body_{m.body()}
{
}
void init(error_code& ec)
{
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
ec.assign(0, ec.category());
return {{const_buffers_type{
body_.data(), body_.size()}, false}};
}
};
};
struct const_body
{
struct value_type{};
@@ -30,7 +64,7 @@ public:
boost::asio::const_buffer;
template<bool isRequest, class Fields>
writer(message<isRequest, const_body, Fields> const&);
writer(header<isRequest, Fields> const&, value_type const&);
void
init(error_code& ec);
@@ -50,7 +84,7 @@ public:
boost::asio::const_buffer;
template<bool isRequest, class Fields>
writer(message<isRequest, mutable_body, Fields>&);
writer(header<isRequest, Fields>&, value_type&);
void
init(error_code& ec);
@@ -115,10 +149,20 @@ public:
}
}
void testBodyWriterCtor()
{
response<deprecated_body> res;
request<deprecated_body> req;
serializer<false, deprecated_body> sr1{res};
serializer<true, deprecated_body> sr2{req};
boost::ignore_unused(sr1, sr2);
}
void
run() override
{
testWriteLimit();
testBodyWriterCtor();
}
};