mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
basic_parser::content_length is stable (API Change):
fix #1375 * The value returned from `basic_parser::content_length` no longer changes as the body of the message is received. Actions Required: * Call `basic_parser::content_length_remaining` instead of `basic_parser::content_length`.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
Version 241:
|
||||
|
||||
* Tidy up a doc code snippet
|
||||
* basic_parser::content_length is stable (API Change)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -239,6 +239,13 @@
|
||||
- `async_accept`, `async_accept_ex`
|
||||
- `async_handshake`, `async_handshake_ex`
|
||||
|
||||
* ([issue 1375]) The value returned from `basic_parser::content_length`
|
||||
no longer changes as the body of the message is received.
|
||||
['Actions Required]: Call `basic_parser::content_length_remaining` instead
|
||||
of `basic_parser::content_length` in order to determine the remaining
|
||||
number of bytes in the body.
|
||||
|
||||
|
||||
[*Examples]
|
||||
|
||||
* All example programs are updated:
|
||||
|
@ -72,6 +72,7 @@ class basic_parser
|
||||
std::uint64_t body_limit_ =
|
||||
default_body_limit(is_request{}); // max payload body
|
||||
std::uint64_t len_ = 0; // size of chunk or body
|
||||
std::uint64_t len0_ = 0; // content length if known
|
||||
std::unique_ptr<char[]> buf_; // temp storage
|
||||
std::size_t buf_len_ = 0; // size of buf_
|
||||
std::size_t skip_ = 0; // resume search here
|
||||
@ -231,6 +232,18 @@ public:
|
||||
boost::optional<std::uint64_t>
|
||||
content_length() const;
|
||||
|
||||
/** Returns the remaining content length if known
|
||||
|
||||
If the message header specifies a Content-Length,
|
||||
the return value will be the number of bytes remaining
|
||||
in the payload body have not yet been parsed.
|
||||
|
||||
@note The return value is undefined unless
|
||||
@ref is_header_done would return `true`.
|
||||
*/
|
||||
boost::optional<std::uint64_t>
|
||||
content_length_remaining() const;
|
||||
|
||||
/** Returns `true` if the message semantics require an end of file.
|
||||
|
||||
Depending on the contents of the header, the parser may
|
||||
|
@ -48,6 +48,17 @@ template<bool isRequest>
|
||||
boost::optional<std::uint64_t>
|
||||
basic_parser<isRequest>::
|
||||
content_length() const
|
||||
{
|
||||
BOOST_ASSERT(is_header_done());
|
||||
if(! (f_ & flagContentLength))
|
||||
return boost::none;
|
||||
return len0_;
|
||||
}
|
||||
|
||||
template<bool isRequest>
|
||||
boost::optional<std::uint64_t>
|
||||
basic_parser<isRequest>::
|
||||
content_length_remaining() const
|
||||
{
|
||||
BOOST_ASSERT(is_header_done());
|
||||
if(! (f_ & flagContentLength))
|
||||
@ -461,6 +472,7 @@ finish_header(error_code& ec, std::true_type)
|
||||
else
|
||||
{
|
||||
len_ = 0;
|
||||
len0_ = 0;
|
||||
state_ = state::complete;
|
||||
}
|
||||
|
||||
@ -796,6 +808,7 @@ do_field(field f,
|
||||
|
||||
ec = {};
|
||||
len_ = v;
|
||||
len0_ = v;
|
||||
f_ |= flagContentLength;
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user