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:
Vinnie Falco
2019-03-29 15:05:30 -07:00
parent 18bf9b4037
commit 51db4d491a
4 changed files with 34 additions and 0 deletions
+13
View File
@@ -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;
}