LCOV - code coverage report
Current view: top level - include/boost/http - message_base.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 11 11
Test Date: 2026-06-13 19:44:58 Functions: 100.0 % 5 5

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
       3                 : // Copyright (c) 2024 Christian Mazakas
       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_MESSAGE_BASE_HPP
      12                 : #define BOOST_HTTP_MESSAGE_BASE_HPP
      13                 : 
      14                 : #include <boost/http/detail/config.hpp>
      15                 : #include <boost/http/fields_base.hpp>
      16                 : #include <boost/core/detail/string_view.hpp>
      17                 : 
      18                 : namespace boost {
      19                 : namespace http {
      20                 : 
      21                 : /** Mixin for modifing common metadata
      22                 :     in HTTP request and response messages.
      23                 : 
      24                 :     This type is useful for modifying common
      25                 :     properties shared by both requests
      26                 :     and responses.
      27                 : 
      28                 :     @see
      29                 :         @ref response,
      30                 :         @ref request,
      31                 :         @ref static_response,
      32                 :         @ref static_request,
      33                 :         @ref metadata.
      34                 : */
      35                 : class message_base
      36                 :     : public fields_base
      37                 : {
      38                 :     friend class request_base;
      39                 :     friend class response_base;
      40                 : 
      41                 :     using fields_base::fields_base;
      42                 : 
      43                 : public:
      44                 :     //--------------------------------------------
      45                 :     //
      46                 :     // Observers
      47                 :     //
      48                 :     //--------------------------------------------
      49                 : 
      50                 :     /** Return the type of payload of this message.
      51                 :     */
      52                 :     auto
      53 HIT      442568 :     payload() const noexcept ->
      54                 :         http::payload
      55                 :     {
      56          442568 :         return h_.md.payload;
      57                 :     }
      58                 : 
      59                 :     /** Return the payload size.
      60                 : 
      61                 :         When @ref payload returns @ref payload::size,
      62                 :         this function returns the number of octets
      63                 :         in the actual message payload.
      64                 : 
      65                 :         @return The number of octets in the
      66                 :         actual message payload.
      67                 :     */
      68                 :     std::uint64_t
      69            8479 :     payload_size() const noexcept
      70                 :     {
      71            8479 :         BOOST_ASSERT(
      72                 :             payload() == payload::size);
      73            8479 :         return h_.md.payload_size;
      74                 :     }
      75                 : 
      76                 :     /** Return true if semantics indicate
      77                 :         connection persistence.
      78                 :     */
      79                 :     bool
      80              24 :     keep_alive() const noexcept
      81                 :     {
      82              24 :         return h_.keep_alive();
      83                 :     }
      84                 : 
      85                 :     /** Return metadata about the message.
      86                 :     */
      87                 :     auto
      88            8991 :     metadata() const noexcept ->
      89                 :         http::metadata const&
      90                 :     {
      91            8991 :         return h_.md;
      92                 :     }
      93                 : 
      94                 :     /** Return true if the message is using a chunked
      95                 :         transfer encoding.
      96                 :     */
      97                 :     bool
      98                 :     chunked() const noexcept
      99                 :     {
     100                 :         return h_.md.transfer_encoding.is_chunked;
     101                 :     }
     102                 : 
     103                 :     /** Return the HTTP-version.
     104                 :     */
     105                 :     http::version
     106             123 :     version() const noexcept
     107                 :     {
     108             123 :         return h_.version;
     109                 :     }
     110                 : 
     111                 :     //--------------------------------------------
     112                 :     //
     113                 :     // Modifiers
     114                 :     //
     115                 :     //--------------------------------------------
     116                 : 
     117                 :     /** Set the payload size.
     118                 : 
     119                 :         @par Exception Safety
     120                 :         Strong guarantee.
     121                 :         Calls to allocate may throw.
     122                 :         Exception thrown if max capacity exceeded.
     123                 : 
     124                 :         @throw std::length_error
     125                 :         Max capacity would be exceeded.
     126                 : 
     127                 :         @param n The payload size to set.
     128                 :     */
     129                 :     BOOST_HTTP_DECL
     130                 :     void
     131                 :     set_payload_size(
     132                 :         std::uint64_t n);
     133                 : 
     134                 :     /** Set the Content-Length to the specified value.
     135                 : 
     136                 :         @par Exception Safety
     137                 :         Strong guarantee.
     138                 :         Calls to allocate may throw.
     139                 :         Exception thrown if max capacity exceeded.
     140                 : 
     141                 :         @throw std::length_error
     142                 :         Max capacity would be exceeded.
     143                 : 
     144                 :         @param n The Content-Length to set.
     145                 :     */
     146                 :     BOOST_HTTP_DECL
     147                 :     void
     148                 :     set_content_length(
     149                 :         std::uint64_t n);
     150                 : 
     151                 :     /** Set whether the payload is chunked.
     152                 : 
     153                 :         @par Exception Safety
     154                 :         Strong guarantee.
     155                 :         Calls to allocate may throw.
     156                 :         Exception thrown if max capacity exceeded.
     157                 : 
     158                 :         @throw std::length_error
     159                 :         Max capacity would be exceeded.
     160                 : 
     161                 :         @param value The value to set.
     162                 :     */
     163                 :     BOOST_HTTP_DECL
     164                 :     void
     165                 :     set_chunked(bool value);
     166                 : 
     167                 :     /** Set whether the connection should stay open.
     168                 : 
     169                 :         Even when keep-alive is set to true, the
     170                 :         semantics of the other header fields may
     171                 :         require the connection to be closed. For
     172                 :         example when there is no content length
     173                 :         specified in a response.
     174                 : 
     175                 :         @par Exception Safety
     176                 :         Strong guarantee.
     177                 :         Calls to allocate may throw.
     178                 :         Exception thrown if max capacity exceeded.
     179                 : 
     180                 :         @throw std::length_error
     181                 :         Max capacity would be exceeded.
     182                 : 
     183                 :         @param value The value to set.
     184                 :     */
     185                 :     BOOST_HTTP_DECL
     186                 :     void
     187                 :     set_keep_alive(bool value);
     188                 : };
     189                 : 
     190                 : } // http
     191                 : } // boost
     192                 : 
     193                 : #endif
        

Generated by: LCOV version 2.3