include/boost/http/metadata.hpp
100.0% Lines (1/0/1)
100.0% List of functions (1/0/1)
Functions (1)
Function
Calls
Lines
Blocks
boost::http::metadata::metadata()
:327
13415x
100.0%
100.0%
| Line | TLA | 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 <system_error> | ||
| 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 : unsigned char | ||
| 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 | std::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 | connection_t() = default; | ||
| 92 | connection_t( | ||
| 93 | std::error_code ec_, | ||
| 94 | std::size_t count_, | ||
| 95 | bool close_, | ||
| 96 | bool keep_alive_, | ||
| 97 | bool upgrade_) noexcept | ||
| 98 | : ec(ec_) | ||
| 99 | , count(count_) | ||
| 100 | , close(close_) | ||
| 101 | , keep_alive(keep_alive_) | ||
| 102 | , upgrade(upgrade_) | ||
| 103 | { | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | }; | ||
| 107 | |||
| 108 | //-------------------------------------------- | ||
| 109 | |||
| 110 | /** Metadata for the Content-Encoding field. | ||
| 111 | */ | ||
| 112 | struct content_encoding_t | ||
| 113 | { | ||
| 114 | /** Error status of Content-Encoding. | ||
| 115 | */ | ||
| 116 | std::error_code ec; | ||
| 117 | |||
| 118 | /** The total number of fields. | ||
| 119 | */ | ||
| 120 | std::size_t count = 0; | ||
| 121 | |||
| 122 | /** The body encoding. | ||
| 123 | */ | ||
| 124 | content_coding coding = | ||
| 125 | content_coding::identity; | ||
| 126 | |||
| 127 | #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND | ||
| 128 | content_encoding_t() = default; | ||
| 129 | content_encoding_t( | ||
| 130 | std::error_code ec_, | ||
| 131 | std::size_t count_, | ||
| 132 | content_coding coding_) noexcept | ||
| 133 | : ec(ec_) | ||
| 134 | , count(count_) | ||
| 135 | , coding(coding_) | ||
| 136 | { | ||
| 137 | } | ||
| 138 | #endif | ||
| 139 | }; | ||
| 140 | |||
| 141 | //-------------------------------------------- | ||
| 142 | |||
| 143 | /** Metadata for the Content-Length field. | ||
| 144 | */ | ||
| 145 | struct content_length_t | ||
| 146 | { | ||
| 147 | /** Error status of Content-Length. | ||
| 148 | */ | ||
| 149 | std::error_code ec; | ||
| 150 | |||
| 151 | /** The total number of fields. | ||
| 152 | */ | ||
| 153 | std::size_t count = 0; | ||
| 154 | |||
| 155 | /** The value as an integer. | ||
| 156 | |||
| 157 | This is only valid when ec does | ||
| 158 | not hold a failure, and when | ||
| 159 | count is greater than zero. | ||
| 160 | */ | ||
| 161 | std::uint64_t value = 0; | ||
| 162 | |||
| 163 | #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND | ||
| 164 | content_length_t() = default; | ||
| 165 | content_length_t( | ||
| 166 | std::error_code ec_, | ||
| 167 | std::size_t count_, | ||
| 168 | std::uint64_t value_) noexcept | ||
| 169 | : ec(ec_) | ||
| 170 | , count(count_) | ||
| 171 | , value(value_) | ||
| 172 | { | ||
| 173 | } | ||
| 174 | #endif | ||
| 175 | }; | ||
| 176 | |||
| 177 | //-------------------------------------------- | ||
| 178 | |||
| 179 | /** Metadata for the Expect field. | ||
| 180 | */ | ||
| 181 | struct expect_t | ||
| 182 | { | ||
| 183 | /** Error status of Expect. | ||
| 184 | */ | ||
| 185 | std::error_code ec; | ||
| 186 | |||
| 187 | /** The total number of fields. | ||
| 188 | */ | ||
| 189 | std::size_t count = 0; | ||
| 190 | |||
| 191 | /** True if Expect is 100-continue. | ||
| 192 | */ | ||
| 193 | bool is_100_continue = false; | ||
| 194 | |||
| 195 | #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND | ||
| 196 | expect_t() = default; | ||
| 197 | expect_t( | ||
| 198 | std::error_code ec_, | ||
| 199 | std::size_t count_, | ||
| 200 | bool is_100_continue_) noexcept | ||
| 201 | : ec(ec_) | ||
| 202 | , count(count_) | ||
| 203 | , is_100_continue(is_100_continue_) | ||
| 204 | { | ||
| 205 | } | ||
| 206 | #endif | ||
| 207 | }; | ||
| 208 | |||
| 209 | //-------------------------------------------- | ||
| 210 | |||
| 211 | /** Metadata for the Transfer-Encoding field. | ||
| 212 | */ | ||
| 213 | struct transfer_encoding_t | ||
| 214 | { | ||
| 215 | /** Error status of Content-Length. | ||
| 216 | */ | ||
| 217 | std::error_code ec; | ||
| 218 | |||
| 219 | /** The total number of fields. | ||
| 220 | */ | ||
| 221 | std::size_t count = 0; | ||
| 222 | |||
| 223 | /** True if valid and chunked is specified last. | ||
| 224 | */ | ||
| 225 | bool is_chunked = false; | ||
| 226 | |||
| 227 | #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND | ||
| 228 | transfer_encoding_t() = default; | ||
| 229 | transfer_encoding_t( | ||
| 230 | std::error_code ec_, | ||
| 231 | std::size_t count_, | ||
| 232 | bool is_chunked_) noexcept | ||
| 233 | : ec(ec_) | ||
| 234 | , count(count_) | ||
| 235 | , is_chunked(is_chunked_) | ||
| 236 | { | ||
| 237 | } | ||
| 238 | #endif | ||
| 239 | }; | ||
| 240 | |||
| 241 | //-------------------------------------------- | ||
| 242 | |||
| 243 | /** Metadata for Upgrade field. | ||
| 244 | */ | ||
| 245 | struct upgrade_t | ||
| 246 | { | ||
| 247 | /** Error status of Upgrade. | ||
| 248 | */ | ||
| 249 | std::error_code ec; | ||
| 250 | |||
| 251 | /** The total number of fields. | ||
| 252 | */ | ||
| 253 | std::size_t count = 0; | ||
| 254 | |||
| 255 | /** True if websocket appears at least once. | ||
| 256 | */ | ||
| 257 | bool websocket = false; | ||
| 258 | |||
| 259 | #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND | ||
| 260 | upgrade_t() = default; | ||
| 261 | upgrade_t( | ||
| 262 | std::error_code ec_, | ||
| 263 | std::size_t count_, | ||
| 264 | bool websocket_) noexcept | ||
| 265 | : ec(ec_) | ||
| 266 | , count(count_) | ||
| 267 | , websocket(websocket_) | ||
| 268 | { | ||
| 269 | } | ||
| 270 | #endif | ||
| 271 | }; | ||
| 272 | |||
| 273 | //-------------------------------------------- | ||
| 274 | |||
| 275 | /** True if payload is manually specified. | ||
| 276 | |||
| 277 | This flag is used to allow the caller | ||
| 278 | to resolve problems with non-compliant | ||
| 279 | values for Content-Length. | ||
| 280 | */ | ||
| 281 | bool payload_override = false; | ||
| 282 | |||
| 283 | /** The type of payload. | ||
| 284 | */ | ||
| 285 | http::payload payload = | ||
| 286 | http::payload::none; | ||
| 287 | |||
| 288 | /** The size of the payload if known. | ||
| 289 | |||
| 290 | This is only valid when @ref payload | ||
| 291 | equals @ref http::payload::size. | ||
| 292 | */ | ||
| 293 | std::uint64_t payload_size = 0; | ||
| 294 | |||
| 295 | //-------------------------------------------- | ||
| 296 | |||
| 297 | // header metadata | ||
| 298 | |||
| 299 | /** Metadata for the Connection field. | ||
| 300 | */ | ||
| 301 | connection_t connection; | ||
| 302 | |||
| 303 | /** Metadata for the Content-Encoding field. | ||
| 304 | */ | ||
| 305 | content_encoding_t content_encoding; | ||
| 306 | |||
| 307 | /** Metadata for the Content-Length field. | ||
| 308 | */ | ||
| 309 | content_length_t content_length; | ||
| 310 | |||
| 311 | /** Metadata for the Expect field. | ||
| 312 | */ | ||
| 313 | expect_t expect; | ||
| 314 | |||
| 315 | /** Metadata for the Transfer-Encoding field. | ||
| 316 | */ | ||
| 317 | transfer_encoding_t transfer_encoding; | ||
| 318 | |||
| 319 | /** Metadata for the Upgrade field. | ||
| 320 | */ | ||
| 321 | upgrade_t upgrade; | ||
| 322 | |||
| 323 | //-------------------------------------------- | ||
| 324 | |||
| 325 | /** Constructor. | ||
| 326 | */ | ||
| 327 | 13415x | metadata() = default; | |
| 328 | }; | ||
| 329 | |||
| 330 | } // http | ||
| 331 | } // boost | ||
| 332 | |||
| 333 | #endif | ||
| 334 |