GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/response.cpp
Date: 2024-08-30 20:13:36
Exec Total Coverage
Lines: 76 76 100.0%
Functions: 11 11 100.0%
Branches: 9 14 64.3%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2024 Christian Mazakas
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/http_proto
9 //
10
11 #include <boost/http_proto/response.hpp>
12 #include <boost/http_proto/response_view.hpp>
13 #include <boost/http_proto/version.hpp>
14
15 #include <utility>
16
17 #include "detail/header_impl.hpp"
18
19 namespace boost {
20 namespace http_proto {
21
22 166 response::
23 166 response() noexcept
24 : fields_view_base(
25 166 &this->fields_base::h_)
26 , message_base(
27 166 detail::kind::response)
28 {
29 166 }
30
31 190 response::
32 response(
33 190 core::string_view s)
34 : fields_view_base(
35 190 &this->fields_base::h_)
36 , message_base(
37 190 detail::kind::response, s)
38 {
39 188 }
40
41 8 response::
42 response(
43 8 std::size_t storage_size)
44 : fields_view_base(
45 8 &this->fields_base::h_)
46 , message_base(
47 8 detail::kind::response, storage_size)
48 {
49 8 }
50
51 20 response::
52 response(
53 std::size_t storage_size,
54 20 std::size_t max_storage_size)
55 : fields_view_base(
56 20 &this->fields_base::h_)
57 , message_base(
58 detail::kind::response,
59 20 storage_size, max_storage_size)
60 {
61 12 }
62
63 8 response::
64 response(
65 8 response&& other) noexcept
66 8 : response()
67 {
68 8 swap(other);
69 8 }
70
71 4 response::
72 response(
73 4 response const& other)
74 : fields_view_base(
75 4 &this->fields_base::h_)
76 4 , message_base(*other.ph_)
77 {
78 4 }
79
80 4 response::
81 response(
82 4 response_view const& other)
83 : fields_view_base(
84 4 &this->fields_base::h_)
85 4 , message_base(*other.ph_)
86 {
87 4 }
88
89 response&
90 2 response::
91 operator=(
92 response&& other) noexcept
93 {
94 response temp(
95 2 std::move(other));
96 2 temp.swap(*this);
97 4 return *this;
98 2 }
99
100 12 response::
101 response(
102 12 http_proto::status sc)
103 : response(
104 12 sc, http_proto::version::http_1_1)
105 {
106 12 }
107
108 28 response::
109 response(
110 http_proto::status sc,
111 28 http_proto::version v)
112 28 : response()
113 {
114
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
28 if( sc != h_.res.status ||
115
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
8 v != h_.version)
116
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
22 set_start_line(sc, v);
117 28 }
118
119 //------------------------------------------------
120
121 void
122 19 response::
123 set_impl(
124 http_proto::status sc,
125 unsigned short si,
126 core::string_view rs,
127 http_proto::version v)
128 {
129 // measure and resize
130 19 auto const vs = to_string(v);
131 auto const n =
132 19 vs.size() + 1 +
133 19 3 + 1 +
134 19 rs.size() +
135 19 2;
136
137
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 detail::prefix_op op(*this, n);
138 19 auto dest = op.prefix_.data();
139
140 19 h_.version = v;
141
1/2
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
19 vs.copy(dest, vs.size());
142 19 dest += vs.size();
143 19 *dest++ = ' ';
144
145 19 h_.res.status = sc;
146 19 h_.res.status_int = si;
147 19 dest[0] = '0' + ((h_.res.status_int / 100) % 10);
148 19 dest[1] = '0' + ((h_.res.status_int / 10) % 10);
149 19 dest[2] = '0' + ((h_.res.status_int / 1) % 10);
150 19 dest[3] = ' ';
151 19 dest += 4;
152
153
1/2
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
19 rs.copy(dest, rs.size());
154 19 dest += rs.size();
155 19 dest[0] = '\r';
156 19 dest[1] = '\n';
157
158
1/2
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
19 h_.on_start_line();
159 19 }
160
161 } // http_proto
162 } // boost
163