GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/request.hpp
Date: 2023-02-11 03:18:39
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 11 11 100.0%
Branches: 0 0 -%

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