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