GCC Code Coverage Report


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