GCC Code Coverage Report


Directory: libs/http_proto/
File: include/boost/http_proto/static_response.hpp
Date: 2025-06-18 09:40:27
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 14 14 100.0%
Branches: 5 6 83.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2025 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/http_proto
8 //
9
10 #ifndef BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP
11 #define BOOST_HTTP_PROTO_STATIC_RESPONSE_HPP
12
13 #include <boost/http_proto/response_base.hpp>
14
15 namespace boost {
16 namespace http_proto {
17
18 /** A modfiable static container for HTTP responses
19 */
20 template<std::size_t Capacity>
21 class static_response
22 : public response_base
23 {
24 alignas(entry)
25 char buf_[Capacity];
26
27 public:
28 /** Constructor
29 */
30 48 static_response() noexcept
31 48 : fields_view_base(&this->fields_base::h_)
32 48 , response_base(buf_, Capacity)
33 {
34 48 }
35
36 /** Constructor
37 */
38 explicit
39 6 static_response(
40 core::string_view s)
41 6 : fields_view_base(&this->fields_base::h_)
42 6 , response_base(s, buf_, Capacity)
43 {
44 6 }
45
46 /** Constructor
47 */
48 24 static_response(
49 http_proto::status sc,
50 http_proto::version v)
51 24 : static_response()
52 {
53
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
24 if( sc != h_.res.status ||
54
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
8 v != h_.version)
55
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 set_start_line(sc, v);
56 24 }
57
58 /** Constructor
59 *
60 * The start-line of the response will contain the standard
61 * text for the supplied status code and the HTTP version
62 * will be defaulted to 1.1.
63 */
64 explicit
65 12 static_response(
66 http_proto::status sc)
67 : static_response(
68 12 sc, http_proto::version::http_1_1)
69 {
70 12 }
71
72 /** Constructor
73 */
74 2 static_response(
75 static_response const& other) noexcept
76 2 : fields_view_base(&this->fields_base::h_)
77 2 , response_base(*other.ph_, buf_, Capacity)
78 {
79 2 }
80
81 /** Constructor
82 */
83 4 static_response(
84 response_view const& other)
85 4 : fields_view_base(&this->fields_base::h_)
86 4 , response_base(*other.ph_, buf_, Capacity)
87 {
88 4 }
89
90 /** Assignment
91 */
92 static_response&
93 1 operator=(
94 static_response const& other) noexcept
95 {
96 1 copy_impl(*other.ph_);
97 1 return *this;
98 }
99
100 /** Assignment
101 */
102 static_response&
103 1 operator=(
104 response_view const& other)
105 {
106 1 copy_impl(*other.ph_);
107 1 return *this;
108 }
109 };
110
111 } // http_proto
112 } // boost
113
114 #endif
115