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 |
|
|
//------------------------------------------------ |
58 |
|
|
|
59 |
|
|
/** Metadata about a request or response |
60 |
|
|
*/ |
61 |
|
|
struct metadata |
62 |
|
|
{ |
63 |
|
|
/** Metadata for the Connection field |
64 |
|
|
*/ |
65 |
|
|
struct connection_t |
66 |
|
|
{ |
67 |
|
|
/** Error status of Connection |
68 |
|
|
*/ |
69 |
|
|
system::error_code ec; |
70 |
|
|
|
71 |
|
|
/** The total number of fields |
72 |
|
|
*/ |
73 |
|
|
std::size_t count = 0; |
74 |
|
|
|
75 |
|
|
/** true if a close token is present |
76 |
|
|
*/ |
77 |
|
|
bool close = false; |
78 |
|
|
|
79 |
|
|
/** true if a keep-alive token is present |
80 |
|
|
*/ |
81 |
|
|
bool keep_alive = false; |
82 |
|
|
|
83 |
|
|
/** true if an upgrade token is present |
84 |
|
|
*/ |
85 |
|
|
bool upgrade = false; |
86 |
|
|
|
87 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
88 |
|
|
constexpr |
89 |
|
2745 |
connection_t() = default; |
90 |
|
|
|
91 |
|
|
constexpr |
92 |
|
15 |
connection_t( |
93 |
|
|
system::error_code ec_, |
94 |
|
|
std::size_t count_, |
95 |
|
|
bool close_, |
96 |
|
|
bool keep_alive_, |
97 |
|
|
bool upgrade_) noexcept |
98 |
|
15 |
: ec(ec_) |
99 |
|
|
, count(count_) |
100 |
|
|
, close(close_) |
101 |
|
|
, keep_alive(keep_alive_) |
102 |
|
15 |
, upgrade(upgrade_) |
103 |
|
|
{ |
104 |
|
15 |
} |
105 |
|
|
#endif |
106 |
|
|
}; |
107 |
|
|
|
108 |
|
|
//-------------------------------------------- |
109 |
|
|
|
110 |
|
|
/** Metadata for the Content-Length field |
111 |
|
|
*/ |
112 |
|
|
struct content_length_t |
113 |
|
|
{ |
114 |
|
|
/** Error status of Content-Length |
115 |
|
|
*/ |
116 |
|
|
system::error_code ec; |
117 |
|
|
|
118 |
|
|
/** The total number of fields |
119 |
|
|
*/ |
120 |
|
|
std::size_t count = 0; |
121 |
|
|
|
122 |
|
|
/** The value as an integer |
123 |
|
|
|
124 |
|
|
This is only valid when ec does |
125 |
|
|
not hold a failure, and when |
126 |
|
|
count is greater than zero. |
127 |
|
|
*/ |
128 |
|
|
std::uint64_t value = 0; |
129 |
|
|
|
130 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
131 |
|
|
constexpr |
132 |
|
2737 |
content_length_t() = default; |
133 |
|
|
|
134 |
|
|
constexpr |
135 |
|
11 |
content_length_t( |
136 |
|
|
system::error_code ec_, |
137 |
|
|
std::size_t count_, |
138 |
|
|
std::uint64_t value_) noexcept |
139 |
|
11 |
: ec(ec_) |
140 |
|
|
, count(count_) |
141 |
|
11 |
, value(value_) |
142 |
|
|
{ |
143 |
|
11 |
} |
144 |
|
|
#endif |
145 |
|
|
}; |
146 |
|
|
|
147 |
|
|
//-------------------------------------------- |
148 |
|
|
|
149 |
|
|
/** Metadata for the Expect field |
150 |
|
|
*/ |
151 |
|
|
struct expect_t |
152 |
|
|
{ |
153 |
|
|
/** Error status of Expect |
154 |
|
|
*/ |
155 |
|
|
system::error_code ec; |
156 |
|
|
|
157 |
|
|
/** The total number of fields |
158 |
|
|
*/ |
159 |
|
|
std::size_t count = 0; |
160 |
|
|
|
161 |
|
|
/** True if Expect is 100-continue |
162 |
|
|
*/ |
163 |
|
|
bool is_100_continue = false; |
164 |
|
|
|
165 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
166 |
|
|
constexpr |
167 |
|
2743 |
expect_t() = default; |
168 |
|
|
|
169 |
|
|
constexpr |
170 |
|
14 |
expect_t( |
171 |
|
|
system::error_code ec_, |
172 |
|
|
std::size_t count_, |
173 |
|
|
bool is_100_continue_) noexcept |
174 |
|
14 |
: ec(ec_) |
175 |
|
|
, count(count_) |
176 |
|
14 |
, is_100_continue(is_100_continue_) |
177 |
|
|
{ |
178 |
|
14 |
} |
179 |
|
|
#endif |
180 |
|
|
}; |
181 |
|
|
|
182 |
|
|
//-------------------------------------------- |
183 |
|
|
|
184 |
|
|
/** Metadata for the Transfer-Encoding field |
185 |
|
|
*/ |
186 |
|
|
struct transfer_encoding_t |
187 |
|
|
{ |
188 |
|
|
/** Error status of Content-Length |
189 |
|
|
*/ |
190 |
|
|
system::error_code ec; |
191 |
|
|
|
192 |
|
|
/** The total number of fields |
193 |
|
|
*/ |
194 |
|
|
std::size_t count = 0; |
195 |
|
|
|
196 |
|
|
/** The total number of codings |
197 |
|
|
*/ |
198 |
|
|
std::size_t codings = 0; |
199 |
|
|
|
200 |
|
|
/** True if valid and chunked is specified last |
201 |
|
|
*/ |
202 |
|
|
bool is_chunked = false; |
203 |
|
|
|
204 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
205 |
|
|
constexpr |
206 |
|
2781 |
transfer_encoding_t() = default; |
207 |
|
|
|
208 |
|
|
constexpr |
209 |
|
20 |
transfer_encoding_t( |
210 |
|
|
system::error_code ec_, |
211 |
|
|
std::size_t count_, |
212 |
|
|
std::size_t codings_, |
213 |
|
|
bool is_chunked_) noexcept |
214 |
|
20 |
: ec(ec_) |
215 |
|
|
, count(count_) |
216 |
|
|
, codings(codings_) |
217 |
|
20 |
, is_chunked(is_chunked_) |
218 |
|
|
{ |
219 |
|
20 |
} |
220 |
|
|
#endif |
221 |
|
|
}; |
222 |
|
|
|
223 |
|
|
//-------------------------------------------- |
224 |
|
|
|
225 |
|
|
/** Metadata for Upgrade field |
226 |
|
|
*/ |
227 |
|
|
struct upgrade_t |
228 |
|
|
{ |
229 |
|
|
/** Error status of Upgrade |
230 |
|
|
*/ |
231 |
|
|
system::error_code ec; |
232 |
|
|
|
233 |
|
|
/** The total number of fields |
234 |
|
|
*/ |
235 |
|
|
std::size_t count = 0; |
236 |
|
|
|
237 |
|
|
/** True if websocket appears at least once |
238 |
|
|
*/ |
239 |
|
|
bool websocket = false; |
240 |
|
|
|
241 |
|
|
#ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND |
242 |
|
|
constexpr |
243 |
|
2738 |
upgrade_t() = default; |
244 |
|
|
|
245 |
|
|
constexpr |
246 |
|
15 |
upgrade_t( |
247 |
|
|
system::error_code ec_, |
248 |
|
|
std::size_t count_, |
249 |
|
|
bool websocket_) noexcept |
250 |
|
15 |
: ec(ec_) |
251 |
|
|
, count(count_) |
252 |
|
15 |
, websocket(websocket_) |
253 |
|
|
{ |
254 |
|
15 |
} |
255 |
|
|
#endif |
256 |
|
|
}; |
257 |
|
|
|
258 |
|
|
//-------------------------------------------- |
259 |
|
|
|
260 |
|
|
/** True if payload is manually specified |
261 |
|
|
|
262 |
|
|
This flag is used to allow the caller |
263 |
|
|
to resolve problems with non-compliant |
264 |
|
|
values for Content-Length. |
265 |
|
|
*/ |
266 |
|
|
bool payload_override = false; |
267 |
|
|
|
268 |
|
|
/** The type of payload |
269 |
|
|
*/ |
270 |
|
|
http_proto::payload payload = |
271 |
|
|
http_proto::payload::none; |
272 |
|
|
|
273 |
|
|
/** The size of the payload if known |
274 |
|
|
|
275 |
|
|
This is only valid when @ref payload |
276 |
|
|
equals @ref http_proto::payload::size. |
277 |
|
|
*/ |
278 |
|
|
std::uint64_t payload_size = 0; |
279 |
|
|
|
280 |
|
|
//-------------------------------------------- |
281 |
|
|
|
282 |
|
|
// header metadata |
283 |
|
|
|
284 |
|
|
/** Metadata for the Connection field. |
285 |
|
|
*/ |
286 |
|
|
connection_t connection; |
287 |
|
|
|
288 |
|
|
/** Metadata for the Content-Length field. |
289 |
|
|
*/ |
290 |
|
|
content_length_t content_length; |
291 |
|
|
|
292 |
|
|
/** Metadata for the Expect field. |
293 |
|
|
*/ |
294 |
|
|
expect_t expect; |
295 |
|
|
|
296 |
|
|
/** Metadata for the Transfer-Encoding field. |
297 |
|
|
*/ |
298 |
|
|
transfer_encoding_t transfer_encoding; |
299 |
|
|
|
300 |
|
|
/** Metadata for the Upgrade field. |
301 |
|
|
*/ |
302 |
|
|
upgrade_t upgrade; |
303 |
|
|
|
304 |
|
|
//-------------------------------------------- |
305 |
|
|
|
306 |
|
|
/** Constructor |
307 |
|
|
*/ |
308 |
|
2733 |
constexpr metadata() = default; |
309 |
|
|
}; |
310 |
|
|
|
311 |
|
|
} // http_proto |
312 |
|
|
} // boost |
313 |
|
|
|
314 |
|
|
#endif |
315 |
|
|
|