forked from boostorg/beast
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:
1 parent
d796319476
commit
b76ab4450a
24 files changed
+358
-107
No files matched your search
@@ -21,6 +21,7 @@ project /boost/beast/test
|
||||
cxx11_variadic_templates
|
||||
]
|
||||
<include>./extern
|
||||
<define>BOOST_BEAST_ALLOW_DEPRECATED
|
||||
;
|
||||
|
||||
path-constant ZLIB_SOURCES :
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
# Official repository: https://github.com/boostorg/beast
|
||||
#
|
||||
|
||||
add_definitions (-DBOOST_BEAST_ALLOW_DEPRECATED)
|
||||
|
||||
GroupSources(include/boost/beast beast)
|
||||
GroupSources(test/extras/include/boost/beast extras)
|
||||
GroupSources(subtree/unit_test/include/boost/beast extras)
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
template<class U>
|
||||
friend
|
||||
bool
|
||||
operator==(test_allocator<T> const&, test_allocator<U> const&) noexcept
|
||||
|
||||
@@ -36,6 +36,42 @@ public:
|
||||
using parser_type =
|
||||
parser<isRequest, string_body>;
|
||||
|
||||
struct deprecated_body
|
||||
{
|
||||
using value_type = std::string;
|
||||
|
||||
class reader
|
||||
{
|
||||
public:
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
reader(message<isRequest, deprecated_body, Fields>&)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
init(boost::optional<std::uint64_t> const&, error_code& ec)
|
||||
{
|
||||
ec = {};
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
std::size_t
|
||||
put(ConstBufferSequence const& buffers, error_code& ec)
|
||||
{
|
||||
ec = {};
|
||||
return boost::asio::buffer_size(buffers);
|
||||
}
|
||||
|
||||
void
|
||||
finish(error_code& ec)
|
||||
{
|
||||
ec = {};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
boost::asio::const_buffer
|
||||
buf(string_view s)
|
||||
@@ -343,6 +379,12 @@ public:
|
||||
BEAST_EXPECT(std::distance(m1.begin(), m1.end()) == 0);
|
||||
}
|
||||
|
||||
void testBodyReaderCtor()
|
||||
{
|
||||
request_parser<deprecated_body> p;
|
||||
boost::ignore_unused(p);
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@@ -351,6 +393,7 @@ public:
|
||||
testNeedMore<multi_buffer>();
|
||||
testGotSome();
|
||||
testIssue818();
|
||||
testBodyReaderCtor();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ struct span_body_test
|
||||
BEAST_EXPECT(req.body().size() == 3);
|
||||
BEAST_EXPECT(B::size(req.body()) == 3);
|
||||
|
||||
B::writer r{req};
|
||||
B::writer r{req, req.body()};
|
||||
error_code ec;
|
||||
r.init(ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
@@ -50,7 +50,7 @@ struct span_body_test
|
||||
using B = span_body<char>;
|
||||
request<B> req;
|
||||
req.body() = span<char>{buf, sizeof(buf)};
|
||||
B::reader w{req};
|
||||
B::reader w{req, req.body()};
|
||||
error_code ec;
|
||||
w.init(boost::none, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
|
||||
@@ -48,9 +48,8 @@ public:
|
||||
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
writer(message<isRequest,
|
||||
unsized_body, Fields> const& msg)
|
||||
: body_(msg.body())
|
||||
writer(header<isRequest, Fields> const&, value_type const& b)
|
||||
: body_(b)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -93,9 +92,8 @@ public:
|
||||
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
writer(message<isRequest,
|
||||
test_body, Fields> const& msg)
|
||||
: body_(msg.body())
|
||||
writer(header<isRequest, Fields> const&, value_type const& b)
|
||||
: body_(b)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -230,9 +228,8 @@ public:
|
||||
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
writer(message<isRequest,
|
||||
fail_body, Fields> const& msg)
|
||||
: body_(msg.body())
|
||||
writer(header<isRequest, Fields> const&, value_type const& b)
|
||||
: body_(b)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -57,11 +57,12 @@ public:
|
||||
|
||||
/** Construct the writer.
|
||||
|
||||
@param msg The message whose body is to be serialized.
|
||||
@param h The header for the message being serialized
|
||||
|
||||
@param body The body being serialized
|
||||
*/
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
explicit
|
||||
BodyWriter(message<isRequest, Body, Fields> const& msg);
|
||||
template<bool isRequest, class Fields>
|
||||
BodyWriter(header<isRequest, Fields> const& h, value_type const& body);
|
||||
|
||||
/** Initialize the writer.
|
||||
|
||||
@@ -120,11 +121,12 @@ struct BodyReader
|
||||
{
|
||||
/** Construct the reader.
|
||||
|
||||
@param msg The message whose body is to be parsed.
|
||||
@param h The header for the message being parsed
|
||||
|
||||
@param body The body to store the parsed results into
|
||||
*/
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
explicit
|
||||
BodyReader(message<isRequest, Body, Fields>& msg);
|
||||
template<bool isRequest, class Fields>
|
||||
BodyReader(header<isRequest, Fields>& h, value_type& body);
|
||||
|
||||
/** Initialize the reader.
|
||||
|
||||
|
||||
Reference in new issue
Block a user