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