src/response.cpp

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