GCC Code Coverage Report


Directory: libs/http_proto/
File: boost/http_proto/response.hpp
Date: 2024-03-11 21:11:07
Exec Total Coverage
Lines: 27 27 100.0%
Functions: 10 10 100.0%
Branches: 0 0 -%

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 #ifndef BOOST_HTTP_PROTO_RESPONSE_HPP
12 #define BOOST_HTTP_PROTO_RESPONSE_HPP
13
14 #include <boost/http_proto/detail/config.hpp>
15 #include <boost/http_proto/message_base.hpp>
16 #include <boost/http_proto/response_view.hpp>
17 #include <boost/http_proto/status.hpp>
18
19 namespace boost {
20 namespace http_proto {
21
22 /** Container for HTTP responses
23 */
24 class BOOST_SYMBOL_VISIBLE
25 response
26 : public message_base
27 {
28 public:
29 /** Constructor
30 */
31 BOOST_HTTP_PROTO_DECL
32 response() noexcept;
33
34 /** Constructor
35 */
36 BOOST_HTTP_PROTO_DECL
37 explicit
38 response(
39 core::string_view s);
40
41 /** Constructor
42
43 The moved-from object will be
44 left in the default-constructed
45 state.
46 */
47 BOOST_HTTP_PROTO_DECL
48 response(response&& other) noexcept;
49
50 /** Constructor
51 */
52 BOOST_HTTP_PROTO_DECL
53 response(response const& other);
54
55 /** Constructor
56 */
57 BOOST_HTTP_PROTO_DECL
58 response(
59 response_view const& other);
60
61 /** Assignment
62 */
63 BOOST_HTTP_PROTO_DECL
64 response&
65 operator=(
66 response&& other) noexcept;
67
68 /** Assignment
69 */
70 response&
71 1 operator=(
72 response const& other)
73 {
74 1 copy_impl(*other.ph_);
75 1 return *this;
76 }
77
78 /** Assignment
79 */
80 response&
81 1 operator=(
82 response_view const& other)
83 {
84 1 copy_impl(*other.ph_);
85 1 return *this;
86 }
87
88 /** Constructor
89 */
90 BOOST_HTTP_PROTO_DECL
91 response(
92 http_proto::status sc,
93 http_proto::version v);
94
95 /** Constructor
96 *
97 * The start-line of the response will contain the standard
98 * text for the supplied status code and the HTTP version
99 * will be defaulted to 1.1.
100 */
101 BOOST_HTTP_PROTO_DECL
102 explicit
103 response(
104 http_proto::status sc);
105
106 /** Return a read-only view to the response
107 */
108 5 operator
109 response_view() const noexcept
110 {
111 5 return response_view(ph_);
112 }
113
114 //--------------------------------------------
115 //
116 // Observers
117 //
118 //--------------------------------------------
119
120 /** Return the reason string
121
122 This field is obsolete in HTTP/1
123 and should only be used for display
124 purposes.
125 */
126 core::string_view
127 28 reason() const noexcept
128 {
129 56 return core::string_view(
130 28 ph_->cbuf + 13,
131 28 ph_->prefix - 15);
132 }
133
134 /** Return the status code
135 */
136 http_proto::status
137 28 status() const noexcept
138 {
139 28 return ph_->res.status;
140 }
141
142 /** Return the status code
143 */
144 unsigned short
145 28 status_int() const noexcept
146 {
147 28 return ph_->res.status_int;
148 }
149
150 /** Return the HTTP version
151 */
152 http_proto::version
153 28 version() const noexcept
154 {
155 28 return ph_->version;
156 }
157
158 //--------------------------------------------
159 //
160 // Modifiers
161 //
162 //--------------------------------------------
163
164 /** Set the version, status code of the response
165
166 The reason phrase will be set to the
167 standard text for the specified status
168 code.
169
170 @par sc The status code. This must not be
171 @ref http_proto::status::unknown.
172
173 @par v The HTTP-version.
174 */
175 void
176 13 set_start_line(
177 http_proto::status sc,
178 http_proto::version v =
179 http_proto::version::http_1_1)
180 {
181 13 set_impl(
182 sc,
183 static_cast<
184 unsigned short>(sc),
185 obsolete_reason(sc),
186 v);
187 13 }
188
189 void
190 6 set_start_line(
191 unsigned short si,
192 core::string_view reason,
193 http_proto::version v)
194 {
195 6 set_impl(
196 int_to_status(si),
197 si,
198 reason,
199 v);
200 6 }
201
202 /** Swap this with another instance
203 */
204 void
205 4 swap(response& other) noexcept
206 {
207 4 h_.swap(other.h_);
208 4 }
209
210 /** Swap two instances
211 */
212 // hidden friend
213 friend
214 void
215 swap(
216 response& t0,
217 response& t1) noexcept
218 {
219 t0.swap(t1);
220 }
221
222 private:
223 BOOST_HTTP_PROTO_DECL
224 void
225 set_impl(
226 http_proto::status sc,
227 unsigned short si,
228 core::string_view reason,
229 http_proto::version v);
230 };
231
232 } // http_proto
233 } // boost
234
235 #endif
236