src/response_head_base.cpp
100.0% Lines (29/29)
100.0% List of functions (3/3)
100.0% Branches (9/9)
Functions (3)
Function
Calls
Lines
Branches
Blocks
boost::burl::response_head_base::response_head_base()
:27
176x
100.0%
–
100.0%
boost::burl::response_head_base::set_start_line(unsigned short, std::basic_string_view<char, std::char_traits<char> >, boost::http::version)
:34
81x
100.0%
100.0%
100.0%
boost::burl::response_head_base::set_version(boost::http::version)
:62
4x
100.0%
100.0%
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2021 Vinnie Falco ([email protected]) | |||
| 3 | // Copyright (c) 2026 Mohammad Nejati | |||
| 4 | // | |||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 7 | // | |||
| 8 | // Official repository: https://github.com/cppalliance/burl | |||
| 9 | // | |||
| 10 | ||||
| 11 | #include <boost/burl/response_head_base.hpp> | |||
| 12 | ||||
| 13 | #include "detail/except.hpp" | |||
| 14 | ||||
| 15 | #include <cstring> | |||
| 16 | ||||
| 17 | namespace boost | |||
| 18 | { | |||
| 19 | namespace burl | |||
| 20 | { | |||
| 21 | ||||
| 22 | namespace | |||
| 23 | { | |||
| 24 | char buf[] = "HTTP/1.1 200 OK\r\n\r\n"; | |||
| 25 | } // namespace | |||
| 26 | ||||
| 27 | 176x | response_head_base:: | ||
| 28 | 176x | response_head_base() noexcept | ||
| 29 | 176x | : response_head_base(buf, 0, 2, 17) | ||
| 30 | { | |||
| 31 | 176x | } | ||
| 32 | ||||
| 33 | void | |||
| 34 | 81x | response_head_base:: | ||
| 35 | set_start_line( | |||
| 36 | unsigned short si, | |||
| 37 | std::string_view reason, | |||
| 38 | http::version v) | |||
| 39 | { | |||
| 40 |
4/4✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 79 times.
|
81x | if(si < 100 || si > 999) | |
| 41 | 2x | detail::throw_invalid_argument("invalid status code"); | ||
| 42 |
1/1✓ Branch 1 taken 79 times.
|
79x | auto const vs = http::to_string(v); | |
| 43 | 233x | auto* dest = splice_prefix_( | ||
| 44 | 0, | |||
| 45 |
1/1✓ Branch 1 taken 75 times.
|
79x | prefix_, | |
| 46 | 79x | 15 + reason.size(), | ||
| 47 | { 13, reason }); | |||
| 48 | 75x | std::memcpy(dest, vs.data(), 8); | ||
| 49 | 75x | dest[8] = ' '; | ||
| 50 | 75x | dest[9] = static_cast<char>('0' + si / 100); | ||
| 51 | 75x | dest[10] = static_cast<char>('0' + (si / 10) % 10); | ||
| 52 | 75x | dest[11] = static_cast<char>('0' + si % 10); | ||
| 53 | 75x | dest[12] = ' '; | ||
| 54 | 75x | dest[13 + reason.size()] = '\r'; | ||
| 55 | 75x | dest[14 + reason.size()] = '\n'; | ||
| 56 | 75x | set_version_(v); | ||
| 57 | 75x | res_.status_int_ = si; | ||
| 58 |
1/1✓ Branch 1 taken 75 times.
|
75x | res_.status_ = http::int_to_status(si); | |
| 59 | 75x | } | ||
| 60 | ||||
| 61 | void | |||
| 62 | 4x | response_head_base:: | ||
| 63 | set_version(http::version v) | |||
| 64 | { | |||
| 65 |
1/1✓ Branch 1 taken 4 times.
|
4x | detach_(); | |
| 66 |
1/1✓ Branch 1 taken 4 times.
|
4x | auto const s = http::to_string(v); | |
| 67 | 4x | std::memcpy(base_(), s.data(), 8); | ||
| 68 | 4x | set_version_(v); | ||
| 69 | 4x | } | ||
| 70 | ||||
| 71 | } // namespace burl | |||
| 72 | } // namespace boost | |||
| 73 |