GCC Code Coverage Report


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