@@ -123,10 +123,6 @@ can_reuse_connection(
123
123
if (response.metadata ().connection .close )
124
124
return false ;
125
125
126
- if (response.payload () == http_proto::payload::size &&
127
- response.payload_size () > 1024 * 1204 )
128
- return false ;
129
-
130
126
return true ;
131
127
}
132
128
@@ -310,23 +306,11 @@ class sink : public http_proto::sink
310
306
}
311
307
};
312
308
313
- class null_sink : public http_proto ::sink
309
+ struct null_sink : http_proto::sink
314
310
{
315
- std::uint64_t limit_;
316
-
317
- public:
318
- null_sink (std::uint64_t limit)
319
- : limit_{ limit }
320
- {
321
- }
322
-
323
311
results
324
312
on_write (buffers::const_buffer cb, bool ) override
325
313
{
326
- if (limit_ < cb.size ())
327
- return { http_proto::error::body_too_large };
328
-
329
- limit_ -= cb.size ();
330
314
return { {}, cb.size () };
331
315
}
332
316
};
@@ -531,15 +515,19 @@ perform_request(
531
515
if (maxredirs-- == 0 )
532
516
throw std::runtime_error{ " Maximum redirects followed" };
533
517
518
+ // Prepare the next request to follow the redirect
519
+
534
520
url = redirect_url (parser.get (), referer);
535
521
536
522
if (!oc.proto_redir .contains (url.scheme_id ()))
537
523
throw std::runtime_error{ " Protocol not supported or disabled" };
538
524
539
525
if (can_reuse_connection (parser.get (), referer, url))
540
526
{
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>();
543
531
auto [ec, _] =
544
532
co_await http_io::async_read (stream, parser, asio::as_tuple);
545
533
if (ec)
0 commit comments