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_METADATA_HPP |
11 |
|
|
#define BOOST_HTTP_PROTO_METADATA_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/http_proto/detail/config.hpp> |
14 |
|
|
#include <boost/http_proto/error.hpp> // VFALCO TEMPORARY |
15 |
|
|
#include <boost/system/error_code.hpp> |
16 |
|
|
#include <cstdint> |
17 |
|
|
#include <cstdlib> |
18 |
|
|
|
19 |
|
|
namespace boost { |
20 |
|
|
namespace http_proto { |
21 |
|
|
|
22 |
|
|
//------------------------------------------------ |
23 |
|
|
|
24 |
|
|
/** Identifies the payload type of a message |
25 |
|
|
*/ |
26 |
|
|
enum class payload |
27 |
|
|
{ |
28 |
|
|
// VFALCO 3 space indent or |
29 |
|
|
// else Doxygen malfunctions |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* This message has no payload |
33 |
|
|
*/ |
34 |
|
|
none |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* The payload is unknown due to errors |
38 |
|
|
*/ |
39 |
|
|
,error |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* This message has a known payload size |
43 |
|
|
*/ |
44 |
|
|
,size |
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* This message contains a chunked payload |
48 |
|
|
*/ |
49 |
|
|
,chunked |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* The payload for this message continues until EOF |
53 |
|
|
*/ |
54 |
|
|
,to_eof |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
enum class content_coding_type { none, gzip, deflate }; |
58 |
|
|
|
59 |
|
|
//------------------------------------------------ |
60 |
|
|
|
61 |
|
|
/** Metadata about a request or response |
62 |
|
|
*/ |
63 |
|
|
struct metadata |
64 |
|
|
{ |
65 |
|
|
/** Metadata for the Connection field |
66 |
|
|
*/ |
67 |
|
|
struct connection_t |
68 |
|
|
{ |
69 |
|
|
/** Error status of Connection |
70 |
|
|
*/ |
71 |
|
|
system::error_code ec; |
72 |
|
|
|
73 |
|
|
/** The total number of fields |
74 |
|
|
*/ |
75 |
|
|
std::size_t count = 0; |
76 |
|
|
|
77 |
|
|
/** true if a close token is present |
78 |
|
|
*/ |
79 |
|
|
bool close = false; |
80 |
|
|
|
81 |
|
|
/** true if a keep-alive token is present |
82 |
|
|
*/ |
83 |
|
|
bool keep_alive = false; |
84 |
|
|
|
85 |
|
|
/** true if an upgrade token is present |
86 |
|
|
*/ |
87 |
|
|
bool upgrade = false; |
88 |
|
|
|
89 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
90 |
|
|
constexpr |
91 |
|
3327 |
connection_t() = default; |
92 |
|
|
|
93 |
|
|
constexpr |
94 |
|
15 |
connection_t( |
95 |
|
|
system::error_code ec_, |
96 |
|
|
std::size_t count_, |
97 |
|
|
bool close_, |
98 |
|
|
bool keep_alive_, |
99 |
|
|
bool upgrade_) noexcept |
100 |
|
15 |
: ec(ec_) |
101 |
|
15 |
, count(count_) |
102 |
|
15 |
, close(close_) |
103 |
|
15 |
, keep_alive(keep_alive_) |
104 |
|
15 |
, upgrade(upgrade_) |
105 |
|
|
{ |
106 |
|
15 |
} |
107 |
|
|
#endif |
108 |
|
|
}; |
109 |
|
|
|
110 |
|
|
//-------------------------------------------- |
111 |
|
|
|
112 |
|
|
/** Metadata for the Content-Length field |
113 |
|
|
*/ |
114 |
|
|
struct content_length_t |
115 |
|
|
{ |
116 |
|
|
/** Error status of Content-Length |
117 |
|
|
*/ |
118 |
|
|
system::error_code ec; |
119 |
|
|
|
120 |
|
|
/** The total number of fields |
121 |
|
|
*/ |
122 |
|
|
std::size_t count = 0; |
123 |
|
|
|
124 |
|
|
/** The value as an integer |
125 |
|
|
|
126 |
|
|
This is only valid when ec does |
127 |
|
|
not hold a failure, and when |
128 |
|
|
count is greater than zero. |
129 |
|
|
*/ |
130 |
|
|
std::uint64_t value = 0; |
131 |
|
|
|
132 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
133 |
|
|
constexpr |
134 |
|
3319 |
content_length_t() = default; |
135 |
|
|
|
136 |
|
|
constexpr |
137 |
|
11 |
content_length_t( |
138 |
|
|
system::error_code ec_, |
139 |
|
|
std::size_t count_, |
140 |
|
|
std::uint64_t value_) noexcept |
141 |
|
11 |
: ec(ec_) |
142 |
|
11 |
, count(count_) |
143 |
|
11 |
, value(value_) |
144 |
|
|
{ |
145 |
|
11 |
} |
146 |
|
|
#endif |
147 |
|
|
}; |
148 |
|
|
|
149 |
|
|
//-------------------------------------------- |
150 |
|
|
|
151 |
|
|
/** Metadata for the Expect field |
152 |
|
|
*/ |
153 |
|
|
struct expect_t |
154 |
|
|
{ |
155 |
|
|
/** Error status of Expect |
156 |
|
|
*/ |
157 |
|
|
system::error_code ec; |
158 |
|
|
|
159 |
|
|
/** The total number of fields |
160 |
|
|
*/ |
161 |
|
|
std::size_t count = 0; |
162 |
|
|
|
163 |
|
|
/** True if Expect is 100-continue |
164 |
|
|
*/ |
165 |
|
|
bool is_100_continue = false; |
166 |
|
|
|
167 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
168 |
|
|
constexpr |
169 |
|
3329 |
expect_t() = default; |
170 |
|
|
|
171 |
|
|
constexpr |
172 |
|
14 |
expect_t( |
173 |
|
|
system::error_code ec_, |
174 |
|
|
std::size_t count_, |
175 |
|
|
bool is_100_continue_) noexcept |
176 |
|
14 |
: ec(ec_) |
177 |
|
14 |
, count(count_) |
178 |
|
14 |
, is_100_continue(is_100_continue_) |
179 |
|
|
{ |
180 |
|
14 |
} |
181 |
|
|
#endif |
182 |
|
|
}; |
183 |
|
|
|
184 |
|
|
//-------------------------------------------- |
185 |
|
|
|
186 |
|
|
/** Metadata for the Transfer-Encoding field |
187 |
|
|
*/ |
188 |
|
|
struct transfer_encoding_t |
189 |
|
|
{ |
190 |
|
|
/** Error status of Content-Length |
191 |
|
|
*/ |
192 |
|
|
system::error_code ec; |
193 |
|
|
|
194 |
|
|
/** The total number of fields |
195 |
|
|
*/ |
196 |
|
|
std::size_t count = 0; |
197 |
|
|
|
198 |
|
|
/** The total number of codings |
199 |
|
|
*/ |
200 |
|
|
std::size_t codings = 0; |
201 |
|
|
|
202 |
|
|
/** True if valid and chunked is specified last |
203 |
|
|
*/ |
204 |
|
|
bool is_chunked = false; |
205 |
|
|
|
206 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
207 |
|
|
constexpr |
208 |
|
3368 |
transfer_encoding_t() = default; |
209 |
|
|
|
210 |
|
|
constexpr |
211 |
|
20 |
transfer_encoding_t( |
212 |
|
|
system::error_code ec_, |
213 |
|
|
std::size_t count_, |
214 |
|
|
std::size_t codings_, |
215 |
|
|
bool is_chunked_) noexcept |
216 |
|
20 |
: ec(ec_) |
217 |
|
20 |
, count(count_) |
218 |
|
20 |
, codings(codings_) |
219 |
|
20 |
, is_chunked(is_chunked_) |
220 |
|
|
{ |
221 |
|
20 |
} |
222 |
|
|
#endif |
223 |
|
|
}; |
224 |
|
|
|
225 |
|
|
//-------------------------------------------- |
226 |
|
|
|
227 |
|
|
/** Metadata for Upgrade field |
228 |
|
|
*/ |
229 |
|
|
struct upgrade_t |
230 |
|
|
{ |
231 |
|
|
/** Error status of Upgrade |
232 |
|
|
*/ |
233 |
|
|
system::error_code ec; |
234 |
|
|
|
235 |
|
|
/** The total number of fields |
236 |
|
|
*/ |
237 |
|
|
std::size_t count = 0; |
238 |
|
|
|
239 |
|
|
/** True if websocket appears at least once |
240 |
|
|
*/ |
241 |
|
|
bool websocket = false; |
242 |
|
|
|
243 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
244 |
|
|
constexpr |
245 |
|
3320 |
upgrade_t() = default; |
246 |
|
|
|
247 |
|
|
constexpr |
248 |
|
15 |
upgrade_t( |
249 |
|
|
system::error_code ec_, |
250 |
|
|
std::size_t count_, |
251 |
|
|
bool websocket_) noexcept |
252 |
|
15 |
: ec(ec_) |
253 |
|
15 |
, count(count_) |
254 |
|
15 |
, websocket(websocket_) |
255 |
|
|
{ |
256 |
|
15 |
} |
257 |
|
|
#endif |
258 |
|
|
}; |
259 |
|
|
|
260 |
|
|
//-------------------------------------------- |
261 |
|
|
|
262 |
|
|
struct content_encoding_t |
263 |
|
|
{ |
264 |
|
|
system::error_code ec; |
265 |
|
|
|
266 |
|
|
std::size_t count = 0; |
267 |
|
|
|
268 |
|
|
content_coding_type coding = content_coding_type::none; |
269 |
|
|
}; |
270 |
|
|
|
271 |
|
|
/** True if payload is manually specified |
272 |
|
|
|
273 |
|
|
This flag is used to allow the caller |
274 |
|
|
to resolve problems with non-compliant |
275 |
|
|
values for Content-Length. |
276 |
|
|
*/ |
277 |
|
|
bool payload_override = false; |
278 |
|
|
|
279 |
|
|
/** The type of payload |
280 |
|
|
*/ |
281 |
|
|
http_proto::payload payload = |
282 |
|
|
http_proto::payload::none; |
283 |
|
|
|
284 |
|
|
/** The size of the payload if known |
285 |
|
|
|
286 |
|
|
This is only valid when @ref payload |
287 |
|
|
equals @ref http_proto::payload::size. |
288 |
|
|
*/ |
289 |
|
|
std::uint64_t payload_size = 0; |
290 |
|
|
|
291 |
|
|
//-------------------------------------------- |
292 |
|
|
|
293 |
|
|
// header metadata |
294 |
|
|
|
295 |
|
|
/** Metadata for the Connection field. |
296 |
|
|
*/ |
297 |
|
|
connection_t connection; |
298 |
|
|
|
299 |
|
|
/** Metadata for the Content-Length field. |
300 |
|
|
*/ |
301 |
|
|
content_length_t content_length; |
302 |
|
|
|
303 |
|
|
/** Metadata for the Expect field. |
304 |
|
|
*/ |
305 |
|
|
expect_t expect; |
306 |
|
|
|
307 |
|
|
/** Metadata for the Transfer-Encoding field. |
308 |
|
|
*/ |
309 |
|
|
transfer_encoding_t transfer_encoding; |
310 |
|
|
|
311 |
|
|
/** Metadata for the Upgrade field. |
312 |
|
|
*/ |
313 |
|
|
upgrade_t upgrade; |
314 |
|
|
|
315 |
|
|
content_encoding_t content_encoding; |
316 |
|
|
|
317 |
|
|
//-------------------------------------------- |
318 |
|
|
|
319 |
|
|
/** Constructor |
320 |
|
|
*/ |
321 |
|
3315 |
constexpr metadata() = default; |
322 |
|
|
}; |
323 |
|
|
|
324 |
|
|
} // http_proto |
325 |
|
|
} // boost |
326 |
|
|
|
327 |
|
|
#endif |
328 |
|
|
|