src/detail/drain_body.cpp

100.0% Lines (2/2) 100.0% List of functions (1/1) 100.0% Branches (1/1)
drain_body.cpp
f(x) Functions (1)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Mohammad Nejati
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/burl
8 //
9
10 #include "drain_body.hpp"
11
12 #include <boost/capy/buffers.hpp>
13 #include <boost/capy/buffers/buffer_slice.hpp>
14 #include <boost/capy/error.hpp>
15 #include <boost/http/error.hpp>
16
17 namespace boost
18 {
19 namespace burl
20 {
21 namespace detail
22 {
23
24 capy::io_task<bool>
25
1/1
✓ Branch 1 taken 22 times.
22x drain_body(
26 http::response_parser& parser,
27 capy::any_stream conn,
28 std::uint64_t limit)
29 {
30 for(;;)
31 {
32 if(parser.is_complete())
33 co_return { {}, true };
34
35 parser.consume_body(
36 (std::numeric_limits<std::uint64_t>::max)());
37
38 system::error_code ec;
39 parser.parse(ec);
40
41 if(ec == http::condition::need_more_input)
42 {
43 if(limit == 0)
44 co_return { {}, false };
45
46 auto mbs = parser.prepare();
47 auto [rec, n] = co_await conn.read_some(
48 capy::buffer_slice(mbs, 0, limit).data());
49 if(rec == capy::cond::eof)
50 {
51 parser.commit_eof();
52 }
53 else if(!rec)
54 {
55 parser.commit(n);
56 limit -= n;
57 }
58 else
59 {
60 co_return { rec, false };
61 }
62
63 continue;
64 }
65
66 if(ec)
67 co_return { std::error_code(ec), false };
68 }
69 44x }
70
71 } // namespace detail
72 } // namespace burl
73 } // namespace boost
74