Skip to content

Commit f3da7c4

Browse files
committed
burl: utilize parser::set_body_limit
1 parent 93bd44f commit f3da7c4

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

example/client/burl/main.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ can_reuse_connection(
123123
if(response.metadata().connection.close)
124124
return false;
125125

126-
if(response.payload() == http_proto::payload::size &&
127-
response.payload_size() > 1024 * 1204)
128-
return false;
129-
130126
return true;
131127
}
132128

@@ -310,23 +306,11 @@ class sink : public http_proto::sink
310306
}
311307
};
312308

313-
class null_sink : public http_proto::sink
309+
struct null_sink : http_proto::sink
314310
{
315-
std::uint64_t limit_;
316-
317-
public:
318-
null_sink(std::uint64_t limit)
319-
: limit_{ limit }
320-
{
321-
}
322-
323311
results
324312
on_write(buffers::const_buffer cb, bool) override
325313
{
326-
if(limit_ < cb.size())
327-
return { http_proto::error::body_too_large };
328-
329-
limit_ -= cb.size();
330314
return { {}, cb.size() };
331315
}
332316
};
@@ -531,15 +515,19 @@ perform_request(
531515
if(maxredirs-- == 0)
532516
throw std::runtime_error{ "Maximum redirects followed" };
533517

518+
// Prepare the next request to follow the redirect
519+
534520
url = redirect_url(parser.get(), referer);
535521

536522
if(!oc.proto_redir.contains(url.scheme_id()))
537523
throw std::runtime_error{ "Protocol not supported or disabled" };
538524

539525
if(can_reuse_connection(parser.get(), referer, url))
540526
{
541-
// read and discard bodies smaller than 1MB
542-
parser.set_body<null_sink>(1024 * 1024);
527+
// read and discard bodies if they are <= 1MB
528+
// open a new connection otherwise.
529+
parser.set_body_limit(1024 * 1024);
530+
parser.set_body<null_sink>();
543531
auto [ec, _] =
544532
co_await http_io::async_read(stream, parser, asio::as_tuple);
545533
if(ec)

include/boost/http_io/impl/read.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class read_body_op
139139
BOOST_ASIO_CORO_REENTER(*this)
140140
{
141141
pr_.parse(ec);
142-
if(ec != http_proto::error::need_data)
142+
if(ec != http_proto::condition::need_more_input)
143143
{
144144
BOOST_ASIO_CORO_YIELD
145145
{

0 commit comments

Comments
 (0)