Parser body_limit is optional (API Change):

API Changes:

The signature of basic_parser<>::body_limit(n) has changed. It now accepts an
optional std::uint64_t. The caller may indicate that no body limit is required
by calling body_limit(boost::none). The default limits remain in place in order
to maintain 'safe by default' behaviour.

closes #1897
closes #1965
This commit is contained in:
Richard Hodges
2020-05-29 20:28:22 +02:00
parent d7f1426f34
commit 0fdf9cb4df
5 changed files with 151 additions and 14 deletions
+14 -8
View File
@@ -573,12 +573,15 @@ basic_parser<isRequest>::
parse_body_to_eof(char const*& p,
std::size_t n, error_code& ec)
{
if(n > body_limit_)
if(body_limit_.has_value())
{
ec = error::body_limit;
return;
if (n > *body_limit_)
{
ec = error::body_limit;
return;
}
*body_limit_ -= n;
}
body_limit_ = body_limit_ - n;
ec = {};
n = this->on_body_impl(string_view{p, n}, ec);
p += n;
@@ -648,12 +651,15 @@ parse_chunk_header(char const*& p0,
}
if(size != 0)
{
if(size > body_limit_)
if (body_limit_.has_value())
{
ec = error::body_limit;
return;
if (size > *body_limit_)
{
ec = error::body_limit;
return;
}
*body_limit_ -= size;
}
body_limit_ -= size;
auto const start = p;
parse_chunk_extensions(p, pend, ec);
if(ec)