src/response.cpp

97.3% Lines (36/37) 100.0% List of functions (8/8) 81.2% Branches (13/16)
response.cpp
f(x) Functions (8)
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 <boost/burl/response.hpp>
11
12 #include "detail/can_reuse_conn.hpp"
13
14 #include <boost/capy/error.hpp>
15 #include <boost/corosio/timeout.hpp>
16
17 #include <chrono>
18 #include <utility>
19
20 namespace boost
21 {
22 namespace burl
23 {
24
25 96x response::response(
26 urls::url url,
27 detail::pooled_connection conn,
28 detail::response_parser parser,
29 std::unique_ptr<detail::parser::decoder> dec,
30 96x std::optional<clock::time_point> deadline)
31 96x : url_(std::move(url))
32 96x , conn_(std::move(conn))
33 96x , parser_(std::move(parser))
34 96x , decoder_(std::move(dec))
35 96x , deadline_(deadline)
36 {
37 96x }
38
39 142x response::response(response&& other) noexcept
40 142x : url_(std::move(other.url_))
41 142x , conn_(std::move(other.conn_))
42 142x , parser_(std::move(other.parser_))
43 142x , decoder_(std::move(other.decoder_))
44 142x , deadline_(other.deadline_)
45 {
46 142x }
47
48 response&
49 2x response::operator=(response&& other) noexcept
50 {
51
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2x if(this != &other)
52 {
53
4/6
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2x if(conn_ && detail::can_reuse_conn(parser_))
54 conn_.return_to_pool();
55 2x url_ = std::move(other.url_);
56 2x conn_ = std::move(other.conn_);
57 2x parser_ = std::move(other.parser_);
58 2x decoder_ = std::move(other.decoder_);
59 2x deadline_ = other.deadline_;
60 }
61 2x return *this;
62 }
63
64 241x response::~response()
65 {
66
6/6
✓ Branch 1 taken 95 times.
✓ Branch 2 taken 146 times.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 33 times.
✓ Branch 6 taken 62 times.
✓ Branch 7 taken 179 times.
241x if(conn_ && detail::can_reuse_conn(parser_))
67 62x conn_.return_to_pool();
68 241x }
69
70 capy::io_task<std::string_view>
71
1/1
✓ Branch 1 taken 30 times.
30x response::try_as_view() &
72 {
73 if(deadline_)
74 co_return co_await corosio::timeout(
75 parser_.read_body(), *deadline_ - clock::now());
76 co_return co_await parser_.read_body();
77 60x }
78
79 capy::task<std::string_view>
80
1/1
✓ Branch 1 taken 8 times.
8x response::as_view() &
81 {
82 auto [ec, body] = co_await try_as_view();
83
84 if(ec)
85 throw std::system_error(ec);
86
87 co_return std::move(body);
88 16x }
89
90 capy::any_buffer_source
91 20x response::as_buffer_source() &
92 {
93 20x return capy::any_buffer_source(&parser_);
94 }
95
96 capy::any_read_source
97 16x response::as_read_source() &
98 {
99 16x return capy::any_read_source(&parser_);
100 }
101
102 } // namespace burl
103 } // namespace boost
104