LCOV - code coverage report
Current view: top level - http_proto - metadata.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 26 26 100.0 %
Date: 2023-01-15 07:18:31 Functions: 11 11 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot 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_types.hpp>
      15             : #include <boost/http_proto/error.hpp> // VFALCO TEMPORARY
      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             :         The function @ref message_view_base::payload_size
      45             :         may be used to obtain the exact number of
      46             :         octets in the actual payload.
      47             :     */
      48             :     ,size
      49             : 
      50             :     /**
      51             :       * The payload for this message continues until EOF
      52             :     */
      53             :     ,to_eof
      54             : 
      55             :     /**
      56             :       * This message contains a chunked payload
      57             :     */
      58             :     ,chunked
      59             : };
      60             : 
      61             : //------------------------------------------------
      62             : 
      63             : /** Metadata about a request or response
      64             : */
      65             : struct metadata
      66             : {
      67             :     /** Metadata for the Connection field
      68             :     */
      69             :     struct connection_t
      70             :     {
      71             :         /** Error status of Connection
      72             :         */
      73             :         error_code ec;
      74             : 
      75             :         /** The total number of fields
      76             :         */
      77             :         std::size_t count = 0;
      78             : 
      79             :         /** true if a close token is present
      80             :         */
      81             :         bool close = false;
      82             : 
      83             :         /** true if a keep-alive token is present
      84             :         */
      85             :         bool keep_alive = false;
      86             : 
      87             :         /** true if an upgrade token is present
      88             :         */
      89             :         bool upgrade = false;
      90             : 
      91             :     #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
      92             :         constexpr
      93         719 :         connection_t() = default;
      94             : 
      95             :         constexpr
      96          15 :         connection_t(
      97             :             error_code ec_,
      98             :             std::size_t count_,
      99             :             bool close_,
     100             :             bool keep_alive_,
     101             :             bool upgrade_) noexcept
     102          15 :             : ec(ec_)
     103             :             , count(count_)
     104             :             , close(close_)
     105             :             , keep_alive(keep_alive_)
     106          15 :             , upgrade(upgrade_)
     107             :         {
     108          15 :         }
     109             :     #endif
     110             :     };
     111             : 
     112             :     //--------------------------------------------
     113             : 
     114             :     /** Metadata for the Content-Length field
     115             :     */
     116             :     struct content_length_t
     117             :     {
     118             :         /** Error status of Content-Length
     119             :         */
     120             :         error_code ec;
     121             : 
     122             :         /** The total number of fields
     123             :         */
     124             :         std::size_t count = 0;
     125             : 
     126             :         /** The value as an integer
     127             : 
     128             :             This is only valid when ec does
     129             :             not hold a failure, and when
     130             :             count is greater than zero.
     131             :         */
     132             :         std::uint64_t value = 0;
     133             : 
     134             :     #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
     135             :         constexpr
     136         711 :         content_length_t() = default;
     137             : 
     138             :         constexpr
     139          11 :         content_length_t(
     140             :             error_code ec_,
     141             :             std::size_t count_,
     142             :             std::uint64_t value_) noexcept
     143          11 :             : ec(ec_)
     144             :             , count(count_)
     145          11 :             , value(value_)
     146             :         {
     147          11 :         }
     148             :     #endif
     149             :     };
     150             : 
     151             :     //--------------------------------------------
     152             : 
     153             :     /** Metadata for the Expect field
     154             :     */
     155             :     struct expect_t
     156             :     {
     157             :         /** Error status of Expect
     158             :         */
     159             :         error_code ec;
     160             : 
     161             :         /** The total number of fields
     162             :         */
     163             :         std::size_t count = 0;
     164             : 
     165             :         /** True if Expect is 100-continue
     166             :         */
     167             :         bool is_100_continue = false;
     168             : 
     169             :     #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
     170             :         constexpr
     171         717 :         expect_t() = default;
     172             : 
     173             :         constexpr
     174          14 :         expect_t(
     175             :             error_code ec_,
     176             :             std::size_t count_,
     177             :             bool is_100_continue_) noexcept
     178          14 :             : ec(ec_)
     179             :             , count(count_)
     180          14 :             , is_100_continue(is_100_continue_)
     181             :         {
     182          14 :         }
     183             :     #endif
     184             :     };
     185             : 
     186             :     //--------------------------------------------
     187             : 
     188             :     /** Metadata for the Transfer-Encoding field
     189             :     */
     190             :     struct transfer_encoding_t
     191             :     {
     192             :         /** Error status of Content-Length
     193             :         */
     194             :         error_code ec;
     195             : 
     196             :         /** The total number of fields
     197             :         */
     198             :         std::size_t count = 0;
     199             : 
     200             :         /** The total number of codings
     201             :         */
     202             :         std::size_t codings = 0;
     203             : 
     204             :         /** True if valid and chunked is specified last
     205             :         */
     206             :         bool is_chunked = false;
     207             : 
     208             :     #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
     209             :         constexpr
     210         756 :         transfer_encoding_t() = default;
     211             : 
     212             :         constexpr
     213          20 :         transfer_encoding_t(
     214             :             error_code ec_,
     215             :             std::size_t count_,
     216             :             std::size_t codings_,
     217             :             bool is_chunked_) noexcept
     218          20 :             : ec(ec_)
     219             :             , count(count_)
     220             :             , codings(codings_)
     221          20 :             , is_chunked(is_chunked_)
     222             :         {
     223          20 :         }
     224             :     #endif
     225             :     };
     226             : 
     227             :     //--------------------------------------------
     228             : 
     229             :     /** Metadata for Upgrade field
     230             :     */
     231             :     struct upgrade_t
     232             :     {
     233             :         /** Error status of Upgrade
     234             :         */
     235             :         error_code ec;
     236             : 
     237             :         /** The total number of fields
     238             :         */
     239             :         std::size_t count = 0;
     240             : 
     241             :         /** True if websocket appears at least once
     242             :         */
     243             :         bool websocket = false;
     244             : 
     245             :     #ifdef BOOST_HTTP_PROTO_AGGREGATE_WORKAROUND
     246             :         constexpr
     247         712 :         upgrade_t() = default;
     248             : 
     249             :         constexpr
     250          15 :         upgrade_t(
     251             :             error_code ec_,
     252             :             std::size_t count_,
     253             :             bool websocket_) noexcept
     254          15 :             : ec(ec_)
     255             :             , count(count_)
     256          15 :             , websocket(websocket_)
     257             :         {
     258          15 :         }
     259             :     #endif
     260             :     };
     261             : 
     262             :     //--------------------------------------------
     263             : 
     264             :     /** True if payload is manually specified
     265             :     */
     266             :     bool manual_payload = 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         707 :     constexpr metadata() = default;
     309             : };
     310             : 
     311             : } // http_proto
     312             : } // boost
     313             : 
     314             : #endif

Generated by: LCOV version 1.15