Change Body::size signature (API Change):

fix #497

This changes the function signature to accept the `value_type`
instead of the entire message.

Actions Required:

* For any user-defined models of Body, change the function signature
  to accept `value_type const&` and modify the function definition
  accordingly.
This commit is contained in:
Vinnie Falco
2017-06-15 19:30:43 -07:00
parent b5be1e0d0d
commit 611e610c0c
11 changed files with 41 additions and 31 deletions

View File

@@ -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: Version 58:
* Fix unaligned reads in utf8-checker * Fix unaligned reads in utf8-checker

View File

@@ -66,6 +66,11 @@ struct Body
class reader; class reader;
class writer; class writer;
// Optional member
static
std::uint64_t
size(value_type const&);
}; };
``` ```

View File

@@ -48,10 +48,10 @@ In this table:
the message body for serialization. the message body for serialization.
] ]
][ ][
[`X::size(m)`] [`X::size(X::value_type const& v)`]
[`std::uint64_t`] [`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, any chunked transfer encoding. When this function is provided,
[link beast.ref.beast__http__message.prepare `message::prepare`] [link beast.ref.beast__http__message.prepare `message::prepare`]
will automatically set the content length field based on the will automatically set the content length field based on the
@@ -80,10 +80,9 @@ struct body
class writer; class writer;
/// Returns the body's payload size /// Returns the body's payload size
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size(message<isRequest, empty_body, Fields> const& m); size(value_type const& v);
} }
``` ```

View File

@@ -48,10 +48,9 @@ struct file_body
@return The size of the file in bytes. @return The size of the file in bytes.
*/ */
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size(message<isRequest, file_body, Fields> const& m); size(value_type const& v);
/** Algorithm for retrieving buffers when serializing. /** Algorithm for retrieving buffers when serializing.
@@ -72,12 +71,11 @@ struct file_body
//[example_http_file_body_2 //[example_http_file_body_2
template<bool isRequest, class Fields>
std::uint64_t std::uint64_t
file_body:: file_body::
size(message<isRequest, file_body, Fields> const& m) size(value_type const& v)
{ {
return boost::filesystem::file_size(m.body); return boost::filesystem::file_size(v);
} }
//] //]

View File

@@ -62,17 +62,17 @@ struct has_value_type<T, beast::detail::void_t<
/** Determine if a @b Body type has a size /** Determine if a @b Body type has a size
This metafunction is equivalent to `std::true_type` if This metafunction is equivalent to `std::true_type` if
Body contains a static member function called `content_lengeth`. Body contains a static member function called `size`.
*/ */
template<class T, class M, class = void> template<class T, class = void>
struct is_body_sized : std::false_type {}; struct is_body_sized : std::false_type {};
template<class T, class M> template<class T>
struct is_body_sized<T, M, beast::detail::void_t< struct is_body_sized<T, beast::detail::void_t<
typename T::value_type, typename T::value_type,
decltype( decltype(
std::declval<std::uint64_t&>() = std::declval<std::uint64_t&>() =
T::size(std::declval<M const&>()), T::size(std::declval<typename T::value_type const&>()),
(void)0)>> : std::true_type {}; (void)0)>> : std::true_type {};
} // detail } // detail

View File

@@ -29,13 +29,11 @@ struct basic_dynamic_body
using value_type = DynamicBuffer; using value_type = DynamicBuffer;
/// Returns the content length of this body in a message. /// Returns the content length of this body in a message.
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size(message<isRequest, size(value_type const& v)
basic_dynamic_body, Fields> const& m)
{ {
return m.body.size(); return v.size();
} }
#if BEAST_DOXYGEN #if BEAST_DOXYGEN

View File

@@ -36,10 +36,9 @@ struct empty_body
}; };
/// Returns the content length of the body in a message. /// Returns the content length of the body in a message.
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size(message<isRequest, empty_body, Fields> const& m) size(empty_body)
{ {
return 0; return 0;
} }

View File

@@ -285,8 +285,7 @@ size() const
static_assert(is_body_reader<Body>::value, static_assert(is_body_reader<Body>::value,
"BodyReader requirements not met"); "BodyReader requirements not met");
return size(detail::is_body_sized< return size(detail::is_body_sized<Body>{});
Body, decltype(*this)>{});
} }
template<bool isRequest, class Body, class Fields> template<bool isRequest, class Body, class Fields>

View File

@@ -558,7 +558,7 @@ private:
boost::optional<std::uint64_t> boost::optional<std::uint64_t>
size(std::true_type) const size(std::true_type) const
{ {
return Body::size(*this); return Body::size(body);
} }
boost::optional<std::uint64_t> boost::optional<std::uint64_t>

View File

@@ -31,13 +31,11 @@ struct string_body
using value_type = std::string; using value_type = std::string;
/// Returns the content length of the body in a message. /// Returns the content length of the body in a message.
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size( size(value_type const& v)
message<isRequest, string_body, Fields> const& m)
{ {
return m.body.size(); return v.size();
} }
#if BEAST_DOXYGEN #if BEAST_DOXYGEN

View File

@@ -32,13 +32,11 @@ struct string_view_body
using value_type = string_view; using value_type = string_view;
/// Returns the content length of this body in a message. /// Returns the content length of this body in a message.
template<bool isRequest, class Fields>
static static
std::uint64_t std::uint64_t
size(message<isRequest, size(value_type const& v)
string_view_body, Fields> const& m)
{ {
return m.body.size(); return v.size();
} }
#if BEAST_DOXYGEN #if BEAST_DOXYGEN