src/detail/can_reuse_conn.cpp
100.0% Lines (15/15)
100.0% List of functions (1/1)
100.0% Branches (11/11)
Functions (1)
Function
Calls
Lines
Branches
Blocks
boost::burl::detail::can_reuse_conn(boost::http::response_parser&)
:20
115x
100.0%
100.0%
100.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 "can_reuse_conn.hpp" | |||
| 11 | ||||
| 12 | namespace boost | |||
| 13 | { | |||
| 14 | namespace burl | |||
| 15 | { | |||
| 16 | namespace detail | |||
| 17 | { | |||
| 18 | ||||
| 19 | bool | |||
| 20 | 115x | can_reuse_conn(http::response_parser& parser) noexcept | ||
| 21 | { | |||
| 22 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 114 times.
|
115x | if(!parser.got_header()) | |
| 23 | 1x | return false; | ||
| 24 | ||||
| 25 |
2/2✓ Branch 2 taken 12 times.
✓ Branch 3 taken 102 times.
|
114x | if(!parser.get().keep_alive()) | |
| 26 | 12x | return false; | ||
| 27 | ||||
| 28 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 66 times.
|
102x | if(!parser.is_complete()) | |
| 29 | { | |||
| 30 | // The rest of the message may already sit in the | |||
| 31 | // parser's buffer; parsing it needs no I/O and makes | |||
| 32 | // the connection reusable. | |||
| 33 | try | |||
| 34 | { | |||
| 35 | 36x | system::error_code ec; | ||
| 36 |
1/1✓ Branch 1 taken 30 times.
|
36x | parser.parse(ec); | |
| 37 | } | |||
| 38 | 6x | catch(...) | ||
| 39 | { | |||
| 40 | // Brotli decoder may have failed to allocate memory. | |||
| 41 | 6x | } | ||
| 42 | } | |||
| 43 | ||||
| 44 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 2 taken 69 times.
|
102x | if(!parser.is_complete()) | |
| 45 | 33x | return false; | ||
| 46 | ||||
| 47 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 65 times.
|
69x | if(parser.has_buffered_data()) | |
| 48 | 4x | return false; | ||
| 49 | ||||
| 50 | 65x | return true; | ||
| 51 | } | |||
| 52 | ||||
| 53 | } // namespace detail | |||
| 54 | } // namespace burl | |||
| 55 | } // namespace boost | |||
| 56 |