GCC Code Coverage Report


Directory: libs/http_proto/
File: boost/http_proto/request.hpp
Date: 2024-03-18 23:12:48
Exec Total Coverage
Lines: 37 38 97.4%
Functions: 12 12 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
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_REQUEST_HPP
11 #define BOOST_HTTP_PROTO_REQUEST_HPP
12
13 #include <boost/http_proto/detail/config.hpp>
14 #include <boost/http_proto/message_base.hpp>
15 #include <boost/http_proto/request_view.hpp>
16
17 namespace boost {
18 namespace http_proto {
19
20 /** Container for HTTP requests
21 */
22 class request final
23 : public message_base
24 {
25 public:
26 /** Constructor
27 */
28 BOOST_HTTP_PROTO_DECL
29 request() noexcept;
30
31 /** Constructor
32 */
33 BOOST_HTTP_PROTO_DECL
34 explicit
35 request(
36 core::string_view s);
37
38 /** Constructor
39 */
40 BOOST_HTTP_PROTO_DECL
41 explicit
42 request(
43 std::size_t initial_size);
44
45 /** Constructor
46 */
47 BOOST_HTTP_PROTO_DECL
48 request(
49 std::size_t initial_size,
50 std::size_t max_capacity);
51
52 /** Constructor
53
54 The moved-from object will be
55 left in the default-constructed
56 state.
57 */
58 BOOST_HTTP_PROTO_DECL
59 request(request&& other) noexcept;
60
61 /** Constructor
62 */
63 BOOST_HTTP_PROTO_DECL
64 request(request const& other);
65
66 /** Constructor
67 */
68 BOOST_HTTP_PROTO_DECL
69 request(
70 request_view const& other);
71
72 /** Assignment
73 */
74 BOOST_HTTP_PROTO_DECL
75 request&
76 operator=(request&&) noexcept;
77
78 /** Assignment
79 */
80 request&
81 4 operator=(request const& other)
82 {
83 4 copy_impl(*other.ph_);
84 4 return *this;
85 }
86
87 /** Assignment
88 */
89 request&
90 operator=(
91 request_view const& other)
92 {
93 copy_impl(*other.ph_);
94 return *this;
95 }
96
97 /** Return a read-only view to the request
98 */
99 2 operator
100 request_view() const noexcept
101 {
102 2 return request_view(ph_);
103 }
104
105 //--------------------------------------------
106 //
107 // Observers
108 //
109 //--------------------------------------------
110
111 /** Return the method as an integral constant
112
113 If the method returned is equal to
114 @ref method::unknown, the method may
115 be obtained as a string instead, by
116 calling @ref method_text.
117 */
118 http_proto::method
119 19 method() const noexcept
120 {
121 19 return ph_->req.method;
122 }
123
124 /** Return the method as a string
125 */
126 core::string_view
127 26 method_text() const noexcept
128 {
129 52 return core::string_view(
130 26 ph_->cbuf,
131 26 ph_->req.method_len);
132 }
133
134 /** Return the request-target string
135 */
136 core::string_view
137 19 target() const noexcept
138 {
139 38 return core::string_view(
140 19 ph_->cbuf +
141 19 ph_->req.method_len + 1,
142 19 ph_->req.target_len);
143 }
144
145 /** Return the HTTP-version
146 */
147 http_proto::version
148 27 version() const noexcept
149 {
150 27 return ph_->version;
151 }
152
153 //--------------------------------------------
154 //
155 // Modifiers
156 //
157 //--------------------------------------------
158
159 /** Set the method of the request to the enum
160 */
161 void
162 2 set_method(
163 http_proto::method m)
164 {
165 2 set_impl(
166 m,
167 to_string(m),
168 target(),
169 version());
170 2 }
171
172 /** Set the method of the request to the string
173 */
174 void
175 6 set_method(
176 core::string_view s)
177 {
178 6 set_impl(
179 string_to_method(s),
180 s,
181 target(),
182 version());
183 6 }
184
185 /** Set the target string of the request
186
187 This function sets the request-target.
188 The caller is responsible for ensuring
189 that the string passed is syntactically
190 valid.
191 */
192 void
193 5 set_target(
194 core::string_view s)
195 {
196 5 set_impl(
197 5 ph_->req.method,
198 method_text(),
199 s,
200 version());
201 5 }
202
203 /** Set the HTTP version of the request
204 */
205 void
206 2 set_version(
207 http_proto::version v)
208 {
209 2 set_impl(
210 2 ph_->req.method,
211 method_text(),
212 target(),
213 v);
214 2 }
215
216 /** Set the method, target, and version of the request
217
218 This is more efficient than setting the
219 properties individually.
220 */
221 void
222 1 set_start_line(
223 http_proto::method m,
224 core::string_view t,
225 http_proto::version v)
226 {
227 1 set_impl(m, to_string(m), t, v);
228 }
229
230 /** Set the method, target, and version of the request
231
232 This is more efficient than setting the
233 properties individually.
234 */
235 void
236 set_start_line(
237 core::string_view m,
238 core::string_view t,
239 http_proto::version v)
240 {
241 set_impl(string_to_method(m), m, t, v);
242 }
243
244 /** Set the Expect header
245 */
246 BOOST_HTTP_PROTO_DECL
247 void
248 set_expect_100_continue(bool b);
249
250 //--------------------------------------------
251
252 /** Swap this with another instance
253 */
254 void
255 44 swap(request& other) noexcept
256 {
257 44 h_.swap(other.h_);
258 44 }
259
260 /** Swap two instances
261 */
262 // hidden friend
263 friend
264 void
265 swap(
266 request& t0,
267 request& t1) noexcept
268 {
269 t0.swap(t1);
270 }
271
272 private:
273 BOOST_HTTP_PROTO_DECL
274 void
275 set_impl(
276 http_proto::method m,
277 core::string_view ms,
278 core::string_view t,
279 http_proto::version v);
280 };
281
282 } // http_proto
283 } // boost
284
285 #endif
286