| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2024 Mohammad Nejati | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/http_proto | ||
| 9 | // | ||
| 10 | |||
| 11 | #ifndef BOOST_HTTP_PROTO_METADATA_HPP | ||
| 12 | #define BOOST_HTTP_PROTO_METADATA_HPP | ||
| 13 | |||
| 14 | #include <boost/http_proto/detail/config.hpp> | ||
| 15 | #include <boost/http_proto/error.hpp> // VFALCO TEMPORARY | ||
| 16 | #include <boost/system/error_code.hpp> | ||
| 17 | #include <cstdint> | ||
| 18 | #include <cstdlib> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace http_proto { | ||
| 22 | |||
| 23 | //------------------------------------------------ | ||
| 24 | |||
| 25 | /** Identifies the payload type of a message | ||
| 26 | */ | ||
| 27 | enum class payload | ||
| 28 | { | ||
| 29 | // VFALCO 3 space indent or | ||
| 30 | // else Doxygen malfunctions | ||
| 31 | |||
| 32 | /** | ||
| 33 | * This message has no payload | ||
| 34 | */ | ||
| 35 | none | ||
| 36 | |||
| 37 | /** | ||
| 38 | * The payload is unknown due to errors | ||
| 39 | */ | ||
| 40 | ,error | ||
| 41 | |||
| 42 | /** | ||
| 43 | * This message has a known payload size | ||
| 44 | */ | ||
| 45 | ,size | ||
| 46 | |||
| 47 | /** | ||
| 48 | * This message contains a chunked payload | ||
| 49 | */ | ||
| 50 | ,chunked | ||
| 51 | |||
| 52 | /** | ||
| 53 | * The payload for this message continues until EOF | ||
| 54 | */ | ||
| 55 | ,to_eof | ||
| 56 | }; | ||
| 57 | |||
| 58 | /** The effective encoding of the body octets. | ||
| 59 | */ | ||
| 60 | enum class | ||
| 61 | encoding | ||
| 62 | { | ||
| 63 | /** | ||
| 64 | * Indicates the body is not encoded. | ||
| 65 | */ | ||
| 66 | identity, | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Indicates the body encoding is unsupported. | ||
| 70 | */ | ||
| 71 | unsupported, | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Indicates the body has deflate applied. | ||
| 75 | */ | ||
| 76 | deflate, | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Indicates the body has gzip applied. | ||
| 80 | */ | ||
| 81 | gzip | ||
| 82 | }; | ||
| 83 | |||
| 84 | //------------------------------------------------ | ||
| 85 | |||
| 86 | /** Metadata about a request or response | ||
| 87 | */ | ||
| 88 | struct metadata | ||
| 89 | { | ||
| 90 | /** Metadata for the Connection field | ||
| 91 | */ | ||
| 92 | struct connection_t | ||
| 93 | { | ||
| 94 | /** Error status of Connection | ||
| 95 | */ | ||
| 96 | system::error_code ec; | ||
| 97 | |||
| 98 | /** The total number of fields | ||
| 99 | */ | ||
| 100 | std::size_t count = 0; | ||
| 101 | |||
| 102 | /** true if a close token is present | ||
| 103 | */ | ||
| 104 | bool close = false; | ||
| 105 | |||
| 106 | /** true if a keep-alive token is present | ||
| 107 | */ | ||
| 108 | bool keep_alive = false; | ||
| 109 | |||
| 110 | /** true if an upgrade token is present | ||
| 111 | */ | ||
| 112 | bool upgrade = false; | ||
| 113 | |||
| 114 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 115 | constexpr | ||
| 116 | 11901 | connection_t() = default; | |
| 117 | |||
| 118 | constexpr | ||
| 119 | 15 | connection_t( | |
| 120 | system::error_code ec_, | ||
| 121 | std::size_t count_, | ||
| 122 | bool close_, | ||
| 123 | bool keep_alive_, | ||
| 124 | bool upgrade_) noexcept | ||
| 125 | 15 | : ec(ec_) | |
| 126 | 15 | , count(count_) | |
| 127 | 15 | , close(close_) | |
| 128 | 15 | , keep_alive(keep_alive_) | |
| 129 | 15 | , upgrade(upgrade_) | |
| 130 | { | ||
| 131 | 15 | } | |
| 132 | #endif | ||
| 133 | }; | ||
| 134 | |||
| 135 | //-------------------------------------------- | ||
| 136 | |||
| 137 | /** Metadata for the Content-Encoding field | ||
| 138 | */ | ||
| 139 | struct content_encoding_t | ||
| 140 | { | ||
| 141 | /** Error status of Content-Encoding | ||
| 142 | */ | ||
| 143 | system::error_code ec; | ||
| 144 | |||
| 145 | /** The total number of fields | ||
| 146 | */ | ||
| 147 | std::size_t count = 0; | ||
| 148 | |||
| 149 | /** The body encoding. | ||
| 150 | */ | ||
| 151 | http_proto::encoding encoding = | ||
| 152 | http_proto::encoding::identity; | ||
| 153 | |||
| 154 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 155 | constexpr | ||
| 156 | 11889 | content_encoding_t() = default; | |
| 157 | |||
| 158 | constexpr | ||
| 159 | 5 | content_encoding_t( | |
| 160 | system::error_code ec_, | ||
| 161 | std::size_t count_, | ||
| 162 | http_proto::encoding encoding_) noexcept | ||
| 163 | 5 | : ec(ec_) | |
| 164 | 5 | , count(count_) | |
| 165 | 5 | , encoding(encoding_) | |
| 166 | { | ||
| 167 | 5 | } | |
| 168 | #endif | ||
| 169 | }; | ||
| 170 | |||
| 171 | //-------------------------------------------- | ||
| 172 | |||
| 173 | /** Metadata for the Content-Length field | ||
| 174 | */ | ||
| 175 | struct content_length_t | ||
| 176 | { | ||
| 177 | /** Error status of Content-Length | ||
| 178 | */ | ||
| 179 | system::error_code ec; | ||
| 180 | |||
| 181 | /** The total number of fields | ||
| 182 | */ | ||
| 183 | std::size_t count = 0; | ||
| 184 | |||
| 185 | /** The value as an integer | ||
| 186 | |||
| 187 | This is only valid when ec does | ||
| 188 | not hold a failure, and when | ||
| 189 | count is greater than zero. | ||
| 190 | */ | ||
| 191 | std::uint64_t value = 0; | ||
| 192 | |||
| 193 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 194 | constexpr | ||
| 195 | 11893 | content_length_t() = default; | |
| 196 | |||
| 197 | constexpr | ||
| 198 | 11 | content_length_t( | |
| 199 | system::error_code ec_, | ||
| 200 | std::size_t count_, | ||
| 201 | std::uint64_t value_) noexcept | ||
| 202 | 11 | : ec(ec_) | |
| 203 | 11 | , count(count_) | |
| 204 | 11 | , value(value_) | |
| 205 | { | ||
| 206 | 11 | } | |
| 207 | #endif | ||
| 208 | }; | ||
| 209 | |||
| 210 | //-------------------------------------------- | ||
| 211 | |||
| 212 | /** Metadata for the Expect field | ||
| 213 | */ | ||
| 214 | struct expect_t | ||
| 215 | { | ||
| 216 | /** Error status of Expect | ||
| 217 | */ | ||
| 218 | system::error_code ec; | ||
| 219 | |||
| 220 | /** The total number of fields | ||
| 221 | */ | ||
| 222 | std::size_t count = 0; | ||
| 223 | |||
| 224 | /** True if Expect is 100-continue | ||
| 225 | */ | ||
| 226 | bool is_100_continue = false; | ||
| 227 | |||
| 228 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 229 | constexpr | ||
| 230 | 11903 | expect_t() = default; | |
| 231 | |||
| 232 | constexpr | ||
| 233 | 14 | expect_t( | |
| 234 | system::error_code ec_, | ||
| 235 | std::size_t count_, | ||
| 236 | bool is_100_continue_) noexcept | ||
| 237 | 14 | : ec(ec_) | |
| 238 | 14 | , count(count_) | |
| 239 | 14 | , is_100_continue(is_100_continue_) | |
| 240 | { | ||
| 241 | 14 | } | |
| 242 | #endif | ||
| 243 | }; | ||
| 244 | |||
| 245 | //-------------------------------------------- | ||
| 246 | |||
| 247 | /** Metadata for the Transfer-Encoding field | ||
| 248 | */ | ||
| 249 | struct transfer_encoding_t | ||
| 250 | { | ||
| 251 | /** Error status of Content-Length | ||
| 252 | */ | ||
| 253 | system::error_code ec; | ||
| 254 | |||
| 255 | /** The total number of fields | ||
| 256 | */ | ||
| 257 | std::size_t count = 0; | ||
| 258 | |||
| 259 | /** The total number of codings | ||
| 260 | */ | ||
| 261 | std::size_t codings = 0; | ||
| 262 | |||
| 263 | /** True if valid and chunked is specified last | ||
| 264 | */ | ||
| 265 | bool is_chunked = false; | ||
| 266 | |||
| 267 | /** The effective body encoding. | ||
| 268 | |||
| 269 | This indicates the type of encoding detected on the body, | ||
| 270 | if the fields contain a valid encoding. Otherwise it will have | ||
| 271 | @ref encoding::identity if the header is invalid. | ||
| 272 | |||
| 273 | Whether or not the message entity is also chunked is set | ||
| 274 | in @ref metadata::is_chunked and not here. | ||
| 275 | */ | ||
| 276 | http_proto::encoding encoding = | ||
| 277 | http_proto::encoding::identity; | ||
| 278 | |||
| 279 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 280 | constexpr | ||
| 281 | 16165 | transfer_encoding_t() = default; | |
| 282 | |||
| 283 | constexpr | ||
| 284 | 20 | transfer_encoding_t( | |
| 285 | system::error_code ec_, | ||
| 286 | std::size_t count_, | ||
| 287 | std::size_t codings_, | ||
| 288 | bool is_chunked_) noexcept | ||
| 289 | 20 | : ec(ec_) | |
| 290 | 20 | , count(count_) | |
| 291 | 20 | , codings(codings_) | |
| 292 | 20 | , is_chunked(is_chunked_) | |
| 293 | 20 | , encoding( | |
| 294 | http_proto::encoding::identity) | ||
| 295 | { | ||
| 296 | 20 | } | |
| 297 | #endif | ||
| 298 | }; | ||
| 299 | |||
| 300 | //-------------------------------------------- | ||
| 301 | |||
| 302 | /** Metadata for Upgrade field | ||
| 303 | */ | ||
| 304 | struct upgrade_t | ||
| 305 | { | ||
| 306 | /** Error status of Upgrade | ||
| 307 | */ | ||
| 308 | system::error_code ec; | ||
| 309 | |||
| 310 | /** The total number of fields | ||
| 311 | */ | ||
| 312 | std::size_t count = 0; | ||
| 313 | |||
| 314 | /** True if websocket appears at least once | ||
| 315 | */ | ||
| 316 | bool websocket = false; | ||
| 317 | |||
| 318 | #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND | ||
| 319 | constexpr | ||
| 320 | 11894 | upgrade_t() = default; | |
| 321 | |||
| 322 | constexpr | ||
| 323 | 15 | upgrade_t( | |
| 324 | system::error_code ec_, | ||
| 325 | std::size_t count_, | ||
| 326 | bool websocket_) noexcept | ||
| 327 | 15 | : ec(ec_) | |
| 328 | 15 | , count(count_) | |
| 329 | 15 | , websocket(websocket_) | |
| 330 | { | ||
| 331 | 15 | } | |
| 332 | #endif | ||
| 333 | }; | ||
| 334 | |||
| 335 | //-------------------------------------------- | ||
| 336 | |||
| 337 | /** True if payload is manually specified | ||
| 338 | |||
| 339 | This flag is used to allow the caller | ||
| 340 | to resolve problems with non-compliant | ||
| 341 | values for Content-Length. | ||
| 342 | */ | ||
| 343 | bool payload_override = false; | ||
| 344 | |||
| 345 | /** The type of payload | ||
| 346 | */ | ||
| 347 | http_proto::payload payload = | ||
| 348 | http_proto::payload::none; | ||
| 349 | |||
| 350 | /** The size of the payload if known | ||
| 351 | |||
| 352 | This is only valid when @ref payload | ||
| 353 | equals @ref http_proto::payload::size. | ||
| 354 | */ | ||
| 355 | std::uint64_t payload_size = 0; | ||
| 356 | |||
| 357 | //-------------------------------------------- | ||
| 358 | |||
| 359 | // header metadata | ||
| 360 | |||
| 361 | /** Metadata for the Connection field. | ||
| 362 | */ | ||
| 363 | connection_t connection; | ||
| 364 | |||
| 365 | /** Metadata for the Content-Encoding field. | ||
| 366 | */ | ||
| 367 | content_encoding_t content_encoding; | ||
| 368 | |||
| 369 | /** Metadata for the Content-Length field. | ||
| 370 | */ | ||
| 371 | content_length_t content_length; | ||
| 372 | |||
| 373 | /** Metadata for the Expect field. | ||
| 374 | */ | ||
| 375 | expect_t expect; | ||
| 376 | |||
| 377 | /** Metadata for the Transfer-Encoding field. | ||
| 378 | */ | ||
| 379 | transfer_encoding_t transfer_encoding; | ||
| 380 | |||
| 381 | /** Metadata for the Upgrade field. | ||
| 382 | */ | ||
| 383 | upgrade_t upgrade; | ||
| 384 | |||
| 385 | //-------------------------------------------- | ||
| 386 | |||
| 387 | /** Constructor | ||
| 388 | */ | ||
| 389 | 11889 | constexpr metadata() = default; | |
| 390 | }; | ||
| 391 | |||
| 392 | } // http_proto | ||
| 393 | } // boost | ||
| 394 | |||
| 395 | #endif | ||
| 396 |