GCC Code Coverage Report


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