diff --git a/CHANGELOG.md b/CHANGELOG.md index db578e8d..ec837686 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +Version 48 + +API Changes: + +* Tidy up chunk decorator + +-------------------------------------------------------------------------------- + Version 47 * Disable operator<< for buffer_body diff --git a/doc/3_4_serializer_streams.qbk b/doc/3_4_serializer_streams.qbk index e94d2f3d..3494a20a 100644 --- a/doc/3_4_serializer_streams.qbk +++ b/doc/3_4_serializer_streams.qbk @@ -27,7 +27,7 @@ template< bool isRequest, class Body, class Fields, - class Decorator = empty_decorator, + class ChunkDecorator = no_chunk_decorator, class Allocator = std::allocator > class serializer; diff --git a/doc/3_6_serializer_buffers.qbk b/doc/3_6_serializer_buffers.qbk index bcccd3c8..5ab46c40 100644 --- a/doc/3_6_serializer_buffers.qbk +++ b/doc/3_6_serializer_buffers.qbk @@ -164,12 +164,11 @@ invoke the decorator with a buffer sequence of size zero. Or more specifically, with an object of type [@http://www.boost.org/doc/html/boost_asio/reference/null_buffers.html `boost::asio::null_buffers`]. -For body chunks the string returned by the decorator must end in a -CRLF (`"\r\n"`) and follow the +For body chunks the string returned by the decorator must follow the [@https://tools.ietf.org/html/rfc7230#section-4.1.1 correct syntax] for the entire chunk extension. For the trailer, the returned string should consist of zero or more lines ending in a CRLF and containing -a field name/value pair in the format prescribed in __rfc7230__. It +a field name/value pair in the format prescribed by __rfc7230__. It is the responsibility of the decorator to manage returned string buffers. The implementation guarantees it will not reference previous strings after subsequent calls. @@ -183,14 +182,14 @@ struct decorator template string_view - operator()(ConstBufferSequence const& buffer) const + operator()(ConstBufferSequence const& buffers) { - s = ";x=" + std::to_string(boost::asio::buffer_size(buffer)) + "\r\n"; + s = ";x=" + std::to_string(boost::asio::buffer_size(buffers)); return s; } string_view - operator()(boost::asio::null_buffers) const + operator()(boost::asio::null_buffers) { return "Result: OK\r\n"; } diff --git a/doc/quickref.xml b/doc/quickref.xml index f5a78b3d..bdff2bef 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -35,12 +35,12 @@ buffer_body dynamic_body empty_body - empty_decorator fields header header_parser message message_parser + no_chunk_decorator request request_parser response diff --git a/include/beast/http/detail/chunk_encode.hpp b/include/beast/http/detail/chunk_encode.hpp index 1eb3cd84..059f3634 100644 --- a/include/beast/http/detail/chunk_encode.hpp +++ b/include/beast/http/detail/chunk_encode.hpp @@ -134,14 +134,6 @@ chunk_crlf() return {"\r\n", 2}; } -/// Returns a buffer sequence holding a CRLF then final chunk -inline -boost::asio::const_buffers_1 -chunk_crlf_final() -{ - return {"\r\n0\r\n\r\n", 7}; -} - /// Returns a buffer sequence holding a final chunk header inline boost::asio::const_buffers_1 diff --git a/include/beast/http/impl/serializer.ipp b/include/beast/http/impl/serializer.ipp index 7768f15f..dcf812c9 100644 --- a/include/beast/http/impl/serializer.ipp +++ b/include/beast/http/impl/serializer.ipp @@ -73,11 +73,11 @@ write_fields(std::ostream& os, //------------------------------------------------------------------------------ template + class ChunkDecorator, class Allocator> serializer:: + ChunkDecorator, Allocator>:: serializer(message const& m, - Decorator const& d, Allocator const& alloc) + ChunkDecorator const& d, Allocator const& alloc) : m_(m) , d_(d) , b_(1024, alloc) @@ -85,11 +85,11 @@ serializer(message const& m, } template + class ChunkDecorator, class Allocator> template void serializer:: + ChunkDecorator, Allocator>:: get(error_code& ec, Visit&& visit) { using boost::asio::buffer_size; @@ -207,6 +207,7 @@ get(error_code& ec, Visit&& visit) sv.data(), sv.size()}; }(), + detail::chunk_crlf(), result->first, detail::chunk_crlf()}; s_ = do_header_c; @@ -251,6 +252,7 @@ get(error_code& ec, Visit&& visit) sv.data(), sv.size()}; }(), + detail::chunk_crlf(), result->first, detail::chunk_crlf()}; s_ = do_body_c + 2; @@ -296,10 +298,10 @@ get(error_code& ec, Visit&& visit) } template + class ChunkDecorator, class Allocator> void serializer:: + ChunkDecorator, Allocator>:: consume(std::size_t n) { using boost::asio::buffer_size; diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index 40190493..f96f9d99 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -356,12 +356,12 @@ class write_msg_op { Stream& s; serializer> sr; + no_chunk_decorator, handler_alloc> sr; data(Handler& h, Stream& s_, message< isRequest, Body, Fields> const& m_) : s(s_) - , sr(m_, empty_decorator{}, + , sr(m_, no_chunk_decorator{}, handler_alloc{h}) { } diff --git a/include/beast/http/serializer.hpp b/include/beast/http/serializer.hpp index 1830c38b..05f6dc49 100644 --- a/include/beast/http/serializer.hpp +++ b/include/beast/http/serializer.hpp @@ -37,13 +37,13 @@ namespace http { @see @ref serializer */ -struct empty_decorator +struct no_chunk_decorator { template string_view operator()(ConstBufferSequence const&) const { - return {"\r\n"}; + return {}; } string_view @@ -115,7 +115,7 @@ struct empty_decorator @tparam Fields The type of fields in the message. - @tparam Decorator The type of chunk decorator to use. + @tparam ChunkDecorator The type of chunk decorator to use. @tparam Allocator The type of allocator to use. @@ -123,7 +123,7 @@ struct empty_decorator */ template< bool isRequest, class Body, class Fields, - class Decorator = empty_decorator, + class ChunkDecorator = no_chunk_decorator, class Allocator = std::allocator > class serializer @@ -172,13 +172,15 @@ class serializer using ch0_t = consuming_buffers>; // crlf using ch1_t = consuming_buffers>; // crlf @@ -188,7 +190,7 @@ class serializer boost::asio::const_buffers_1>>; // crlf message const& m_; - Decorator d_; + ChunkDecorator d_; boost::optional rd_; buffer_type b_; boost::variant const& msg, - Decorator const& decorator = Decorator{}, + ChunkDecorator const& decorator = ChunkDecorator{}, Allocator const& alloc = Allocator{}); /** Returns `true` if we will pause after writing the complete header. @@ -335,18 +337,18 @@ public: */ template< bool isRequest, class Body, class Fields, - class Decorator = empty_decorator, + class ChunkDecorator = no_chunk_decorator, class Allocator = std::allocator> inline serializer::type, + typename std::decay::type, typename std::decay::type> make_serializer(message const& m, - Decorator const& decorator = Decorator{}, + ChunkDecorator const& decorator = ChunkDecorator{}, Allocator const& allocator = Allocator{}) { return serializer::type, + typename std::decay::type, typename std::decay::type>{ m, decorator, allocator}; } diff --git a/test/http/write.cpp b/test/http/write.cpp index dd9dbeac..d626f927 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -759,7 +759,7 @@ public: template + class Decorator = no_chunk_decorator> void do_write(Stream& stream, message< isRequest, Body, Fields> const& m, error_code& ec, @@ -780,7 +780,7 @@ public: template + class Decorator = no_chunk_decorator> void do_async_write(Stream& stream, message const& m, @@ -802,17 +802,20 @@ public: struct test_decorator { + std::string s; + template string_view - operator()(ConstBufferSequence const&) const + operator()(ConstBufferSequence const& buffers) { - return {";x\r\n"}; + s = ";x=" + std::to_string(boost::asio::buffer_size(buffers)); + return s; } string_view - operator()(boost::asio::null_buffers) const + operator()(boost::asio::null_buffers) { - return {"F: v\r\n"}; + return "Result: OK\r\n"; } };