diff --git a/CHANGELOG.md b/CHANGELOG.md index b55afc3b..405c3766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +Version 59: + +* Integrated Beast INTERFACE (cmake) + +API Changes: + +* Change Body::size signature (API Change): + +Actions Required: + +* For any user-defined models of Body, change the function signature + to accept `value_type const&` and modify the function definition + accordingly. + +-------------------------------------------------------------------------------- + Version 58: * Fix unaligned reads in utf8-checker diff --git a/doc/5_09_custom_body.qbk b/doc/5_09_custom_body.qbk index 6f7294ed..2872e1ef 100644 --- a/doc/5_09_custom_body.qbk +++ b/doc/5_09_custom_body.qbk @@ -66,6 +66,11 @@ struct Body class reader; class writer; + + // Optional member + static + std::uint64_t + size(value_type const&); }; ``` diff --git a/doc/concept/Body.qbk b/doc/concept/Body.qbk index 0214dffa..8a334ecb 100644 --- a/doc/concept/Body.qbk +++ b/doc/concept/Body.qbk @@ -48,10 +48,10 @@ In this table: the message body for serialization. ] ][ - [`X::size(m)`] + [`X::size(X::value_type const& v)`] [`std::uint64_t`] [ - If present, returns the serialized size of `m.body` not including + If present, returns the serialized size of `v` not including any chunked transfer encoding. When this function is provided, [link beast.ref.beast__http__message.prepare `message::prepare`] will automatically set the content length field based on the @@ -80,10 +80,9 @@ struct body class writer; /// Returns the body's payload size - template static std::uint64_t - size(message const& m); + size(value_type const& v); } ``` diff --git a/example/http-server/file_body.hpp b/example/http-server/file_body.hpp index 512381f6..5faf75b5 100644 --- a/example/http-server/file_body.hpp +++ b/example/http-server/file_body.hpp @@ -48,10 +48,9 @@ struct file_body @return The size of the file in bytes. */ - template static std::uint64_t - size(message const& m); + size(value_type const& v); /** Algorithm for retrieving buffers when serializing. @@ -72,12 +71,11 @@ struct file_body //[example_http_file_body_2 -template std::uint64_t file_body:: -size(message const& m) +size(value_type const& v) { - return boost::filesystem::file_size(m.body); + return boost::filesystem::file_size(v); } //] diff --git a/include/beast/http/detail/type_traits.hpp b/include/beast/http/detail/type_traits.hpp index 4479f2ae..ea2e2284 100644 --- a/include/beast/http/detail/type_traits.hpp +++ b/include/beast/http/detail/type_traits.hpp @@ -62,17 +62,17 @@ struct has_value_type +template struct is_body_sized : std::false_type {}; -template -struct is_body_sized +struct is_body_sized() = - T::size(std::declval()), + T::size(std::declval()), (void)0)>> : std::true_type {}; } // detail diff --git a/include/beast/http/dynamic_body.hpp b/include/beast/http/dynamic_body.hpp index 7397bc30..e6bb94f4 100644 --- a/include/beast/http/dynamic_body.hpp +++ b/include/beast/http/dynamic_body.hpp @@ -29,13 +29,11 @@ struct basic_dynamic_body using value_type = DynamicBuffer; /// Returns the content length of this body in a message. - template static std::uint64_t - size(message const& m) + size(value_type const& v) { - return m.body.size(); + return v.size(); } #if BEAST_DOXYGEN diff --git a/include/beast/http/empty_body.hpp b/include/beast/http/empty_body.hpp index 1a563c60..59b31d5d 100644 --- a/include/beast/http/empty_body.hpp +++ b/include/beast/http/empty_body.hpp @@ -36,10 +36,9 @@ struct empty_body }; /// Returns the content length of the body in a message. - template static std::uint64_t - size(message const& m) + size(empty_body) { return 0; } diff --git a/include/beast/http/impl/message.ipp b/include/beast/http/impl/message.ipp index 45f6774f..45d9cf8c 100644 --- a/include/beast/http/impl/message.ipp +++ b/include/beast/http/impl/message.ipp @@ -285,8 +285,7 @@ size() const static_assert(is_body_reader::value, "BodyReader requirements not met"); - return size(detail::is_body_sized< - Body, decltype(*this)>{}); + return size(detail::is_body_sized{}); } template diff --git a/include/beast/http/message.hpp b/include/beast/http/message.hpp index f9808dd8..fdf77359 100644 --- a/include/beast/http/message.hpp +++ b/include/beast/http/message.hpp @@ -558,7 +558,7 @@ private: boost::optional size(std::true_type) const { - return Body::size(*this); + return Body::size(body); } boost::optional diff --git a/include/beast/http/string_body.hpp b/include/beast/http/string_body.hpp index 6bb357e8..eaccc9dc 100644 --- a/include/beast/http/string_body.hpp +++ b/include/beast/http/string_body.hpp @@ -31,13 +31,11 @@ struct string_body using value_type = std::string; /// Returns the content length of the body in a message. - template static std::uint64_t - size( - message const& m) + size(value_type const& v) { - return m.body.size(); + return v.size(); } #if BEAST_DOXYGEN diff --git a/include/beast/http/string_view_body.hpp b/include/beast/http/string_view_body.hpp index 06b3d69a..6a7df6b2 100644 --- a/include/beast/http/string_view_body.hpp +++ b/include/beast/http/string_view_body.hpp @@ -32,13 +32,11 @@ struct string_view_body using value_type = string_view; /// Returns the content length of this body in a message. - template static std::uint64_t - size(message const& m) + size(value_type const& v) { - return m.body.size(); + return v.size(); } #if BEAST_DOXYGEN