beast: Inapropriate error::body_limit, parsing chunked and multipart reponses

I am using beast with boost 1.72.

This is what I think is wrong.

  1. body limit is calculated incorrectly
  2. body limit is calculated when it should not

About 1, body limit is calculated incorrectly: The calculation of the body limit does not only count the newly received data, but also the old data not yet processed because of a need_more.

This can be observed by adding a counter to on_body_impl of a custom parser . Have it add the size of the string_view and return need_more.

std::size_t on_body_impl(beast::string_view s,
  beast::error_code& ec) {

  counter_ += s.size();
  ec = beast::http::error::need_more;
}

You will receive error::body_limit around the time the counter_ has grown to the body_limit. Clearly this is wrong, because the actual body size at that time is s.size(). Every time you return need_more, newly received data is added to s, but the counter is counting the entire size of s, counting the previously received data again and again.

About 2, body limit is calculated when it should not

I am using a custom parser to receive HTTP responses that continuously send status information, or motion JPEGs. None of the data read by async_read will be actually added to the message body of the parser, but still error::body_limit will eventually fire.

Here is an example of a web server sending a multipart response. http://88.53.197.250/axis-cgi/mjpg/video.cgi?resolution=320x240 It’s a rather slow site, so it takes a while to exceed the default limit.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (8 by maintainers)

Commits related to this issue

Most upvoted comments

indentation

better?