My starting point is to create a simple downloader code from the boost beast http_client_async example at boost http_client_async. In this scenario i want to write the received body into a file.
So I exchanged the string body into a file_body, to write the received data:
http::response_parser<http::file_body> res_;
And simply rewrote the on_write method to
void on_write( boost::system::error_code ec,
std::size_t bytes_transferred )
{
boost::ignore_unused(bytes_transferred);
if(ec)
return fail(ec, "write");
boost::system::error_code ec_file;
res_.body().open("myTest.txt", boost::beast::file_mode::write, ec_file);
// test for ec_file missing
// Receive the HTTP response
http::async_read(socket_, buffer_, res_,
std::bind(
&session::on_read,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
So but now, some of the received data bodies are to big:
read: body limit exceeded
and I try to increase the body limit.
In case of using a parser instead of a message, the size limit of the requested body can be changed with the body_limit()
method.
Is there an easy way to increase the body size limit from a message as well?
response_parser<http::file_body>
instead ofresponse<http::string_body>
is the best way to go, I think. It got confused here. A response parser is not a message. When trying to get the body for calling open, res_ needs a call tores_.get().body().open("myTest.txt", boost::beast::file_mode::write, ec_file);
. The response_parserres_
is able to handle the member variable body_limit(). – Scribbler