src/response.cpp
97.1% Lines (33/34)
100.0% List of functions (8/8)
83.3% Branches (15/18)
Functions (8)
Function
Calls
Lines
Branches
Blocks
boost::burl::response::response(boost::urls::url, boost::burl::detail::pooled_connection, boost::http::response_parser, std::optional<std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > >)
:25
100x
100.0%
–
100.0%
boost::burl::response::response(boost::burl::response&&)
:37
115x
100.0%
–
100.0%
boost::burl::response::operator=(boost::burl::response&&)
:46
2x
88.9%
62.5%
89.0%
boost::burl::response::~response()
:60
223x
100.0%
100.0%
100.0%
boost::burl::response::try_as_view() &
:67
33x
100.0%
100.0%
44.0%
boost::burl::response::as_view() &
:90
8x
100.0%
100.0%
44.0%
boost::burl::response::as_buffer_source() &
:101
36x
100.0%
–
100.0%
boost::burl::response::as_read_source() &
:107
16x
100.0%
100.0%
78.0%
| 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/capy/timeout.hpp> | |||
| 16 | ||||
| 17 | #include <chrono> | |||
| 18 | #include <utility> | |||
| 19 | ||||
| 20 | namespace boost | |||
| 21 | { | |||
| 22 | namespace burl | |||
| 23 | { | |||
| 24 | ||||
| 25 | 100x | response::response( | ||
| 26 | urls::url url, | |||
| 27 | detail::pooled_connection conn, | |||
| 28 | http::response_parser parser, | |||
| 29 | 100x | std::optional<clock::time_point> deadline) | ||
| 30 | 100x | : url_(std::move(url)) | ||
| 31 | 100x | , conn_(std::move(conn)) | ||
| 32 | 100x | , parser_(std::move(parser)) | ||
| 33 | 100x | , deadline_(deadline) | ||
| 34 | { | |||
| 35 | 100x | } | ||
| 36 | ||||
| 37 | 115x | response::response(response&& other) noexcept | ||
| 38 | 115x | : url_(std::move(other.url_)) | ||
| 39 | 115x | , conn_(std::move(other.conn_)) | ||
| 40 | 115x | , parser_(std::move(other.parser_)) | ||
| 41 | 115x | , deadline_(other.deadline_) | ||
| 42 | { | |||
| 43 | 115x | } | ||
| 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 | 223x | response::~response() | ||
| 61 | { | |||
| 62 |
6/6✓ Branch 1 taken 99 times.
✓ Branch 2 taken 124 times.
✓ Branch 4 taken 63 times.
✓ Branch 5 taken 36 times.
✓ Branch 6 taken 63 times.
✓ Branch 7 taken 160 times.
|
223x | if(conn_ && detail::can_reuse_conn(parser_)) | |
| 63 | 63x | conn_.return_to_pool(); | ||
| 64 | 223x | } | ||
| 65 | ||||
| 66 | capy::io_task<std::string_view> | |||
| 67 |
1/1✓ Branch 1 taken 33 times.
|
33x | response::try_as_view() & | |
| 68 | { | |||
| 69 | if(parser_.is_complete()) | |||
| 70 | co_return { {}, parser_.body() }; | |||
| 71 | ||||
| 72 | if(deadline_) | |||
| 73 | { | |||
| 74 | auto dur = *deadline_ - clock::now(); | |||
| 75 | if(dur <= clock::duration::zero()) | |||
| 76 | co_return { capy::error::timeout, {} }; | |||
| 77 | ||||
| 78 | auto [rec] = co_await capy::timeout(parser_.read(conn_), dur); | |||
| 79 | if(rec) | |||
| 80 | co_return { rec, {} }; | |||
| 81 | } | |||
| 82 | else if(auto [rec] = co_await parser_.read(conn_); rec) | |||
| 83 | { | |||
| 84 | co_return { rec, {} }; | |||
| 85 | } | |||
| 86 | co_return { {}, parser_.body() }; | |||
| 87 | 66x | } | ||
| 88 | ||||
| 89 | capy::task<std::string_view> | |||
| 90 |
1/1✓ Branch 1 taken 8 times.
|
8x | response::as_view() & | |
| 91 | { | |||
| 92 | auto [ec, body] = co_await try_as_view(); | |||
| 93 | ||||
| 94 | if(ec) | |||
| 95 | throw std::system_error(ec); | |||
| 96 | ||||
| 97 | co_return std::move(body); | |||
| 98 | 16x | } | ||
| 99 | ||||
| 100 | capy::any_buffer_source | |||
| 101 | 36x | response::as_buffer_source() & | ||
| 102 | { | |||
| 103 | 36x | return parser_.source_for(conn_); | ||
| 104 | } | |||
| 105 | ||||
| 106 | capy::any_read_source | |||
| 107 | 16x | response::as_read_source() & | ||
| 108 | { | |||
| 109 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16x | return as_buffer_source(); // TODO | |
| 110 | } | |||
| 111 | ||||
| 112 | } // namespace burl | |||
| 113 | } // namespace boost | |||
| 114 |