LCOV - code coverage report
Current view: top level - boost/http_proto/request.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 6 6
Test Date: 2025-06-18 09:40:26 Functions: 100.0 % 2 2

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2025 Mohammad Nejati
       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_REQUEST_HPP
      11              : #define BOOST_HTTP_PROTO_REQUEST_HPP
      12              : 
      13              : #include <boost/http_proto/request_base.hpp>
      14              : 
      15              : namespace boost {
      16              : namespace http_proto {
      17              : 
      18              : /** Container for HTTP requests
      19              : */
      20              : class request
      21              :     : public request_base
      22              : {
      23              : public:
      24              :     /** Constructor
      25              :     */
      26              :     BOOST_HTTP_PROTO_DECL
      27              :     request() noexcept;
      28              : 
      29              :     /** Constructor
      30              :     */
      31              :     BOOST_HTTP_PROTO_DECL
      32              :     explicit
      33              :     request(
      34              :         core::string_view s);
      35              : 
      36              :     /** Constructor
      37              : 
      38              :         Construct a request container which allocates
      39              :         `storage_size` bytes for storing the header.
      40              :         Attempting to grow the container beyond
      41              :         this amount will result in an exception.
      42              :         The storage is also used internally to store
      43              :         instances of an implementation-defined type.
      44              :         The requested number of bytes will be aligned
      45              :         accordingly (currently the alignment requirement is 4).
      46              : 
      47              :         <br/>
      48              : 
      49              :         This constructor is useful when an upper-bound size
      50              :         of the request is known ahead of time and we want
      51              :         to prevent reallocations.
      52              : 
      53              :         <br/>
      54              : 
      55              :         Passing an initial storage size of `0` does not
      56              :         throw and the maximum capacity is set to an
      57              :         implementation-defined limit observable via
      58              :         @ref max_capacity_in_bytes().
      59              : 
      60              :         @param storage_size The initial and final size of
      61              :         the storage.
      62              : 
      63              :         @code
      64              :         boost::http_proto::request
      65              :         make_request(std::string_view host)
      66              :         {
      67              :             std::size_t size = 4096;
      68              :             // req.buffer() is now stable
      69              :             boost::http_proto::request req(size);
      70              :             BOOST_ASSERT(
      71              :                 req.max_capacity_in_bytes(), 4096);
      72              : 
      73              :             // uses spare capacity so that reallocations
      74              :             // are avoided
      75              :             req.append(
      76              :                 boost::http_proto::field::host, host);
      77              :             req.append(
      78              :                 boost::http_proto::field::connection, "close");
      79              :             return req;
      80              :         }
      81              :         @endcode
      82              :     */
      83              :     BOOST_HTTP_PROTO_DECL
      84              :     explicit
      85              :     request(
      86              :         std::size_t storage_size);
      87              : 
      88              :     /** Constructor
      89              : 
      90              :         Construct a request container which allocates
      91              :         `storage_size` bytes for storing the header, with an
      92              :         upper limit of `max_storage_size`. Attempting to
      93              :         grow the container beyond its maximum will result in
      94              :         an exception. The storage is also used internally to
      95              :         store instances of an implementation-defined type.
      96              :         Both values will be aligned accordingly (currently
      97              :         the alignment requirement is 4).
      98              : 
      99              :         <br/>
     100              : 
     101              :         This constructor is useful when there's a best-fit
     102              :         guess for an initial header size but we still wish
     103              :         to permit reallocating and growing the container to
     104              :         some upper limit.
     105              : 
     106              :         <br/>
     107              : 
     108              :         Passing an initial size of `0` does not throw.
     109              : 
     110              :         @param storage_size The initial size of the storage.
     111              : 
     112              :         @param max_storage_size The maximum size of the
     113              :         allocated storage. Any operation that attempts to
     114              :         grow the container beyond this value throws
     115              :         `std::length_error`.
     116              : 
     117              :         @throws std::length_error Thrown if `size > max_size`
     118              : 
     119              :         @code
     120              :         boost::http_proto::reqest
     121              :         make_reqest(std::string_view host)
     122              :         {
     123              :             std::size_t size = 4096;
     124              :             boost::http_proto::reqest req(size, 2 * size);
     125              :             BOOST_ASSERT(
     126              :                 req.max_capacity_in_bytes(), 2 * 4096);
     127              : 
     128              :             // uses spare capacity so that reallocations
     129              :             // are avoided
     130              :             req.append(
     131              :                 boost::http_proto::field::host, host);
     132              :             req.append(
     133              :                 boost::http_proto::field::connection, "close");
     134              :             return req;
     135              :         }
     136              :         @endcode
     137              :     */
     138              :     BOOST_HTTP_PROTO_DECL
     139              :     request(
     140              :         std::size_t storage_size,
     141              :         std::size_t max_storage_size);
     142              : 
     143              :     /** Constructor
     144              : 
     145              :         The moved-from object will be
     146              :         left in the default-constructed
     147              :         state.
     148              :     */
     149              :     BOOST_HTTP_PROTO_DECL
     150              :     request(request&& other) noexcept;
     151              : 
     152              :     /** Constructor
     153              :     */
     154              :     BOOST_HTTP_PROTO_DECL
     155              :     request(request const& other);
     156              : 
     157              :     /** Constructor
     158              :     */
     159              :     BOOST_HTTP_PROTO_DECL
     160              :     request(
     161              :         request_view const& other);
     162              : 
     163              :     /** Assignment
     164              :     */
     165              :     BOOST_HTTP_PROTO_DECL
     166              :     request&
     167              :     operator=(request&&) noexcept;
     168              : 
     169              :     /** Assignment
     170              :     */
     171              :     request&
     172            4 :     operator=(
     173              :         request const& other)
     174              :     {
     175            4 :         copy_impl(*other.ph_);
     176            4 :         return *this;
     177              :     }
     178              : 
     179              :     /** Assignment
     180              :     */
     181              :     request&
     182              :     operator=(
     183              :         request_view const& other)
     184              :     {
     185              :         copy_impl(*other.ph_);
     186              :         return *this;
     187              :     }
     188              : 
     189              :     //--------------------------------------------
     190              : 
     191              :     /** Swap this with another instance
     192              :     */
     193              :     void
     194           44 :     swap(request& other) noexcept
     195              :     {
     196           44 :         h_.swap(other.h_);
     197           44 :     }
     198              : 
     199              :     /** Swap two instances
     200              :     */
     201              :     // hidden friend
     202              :     friend
     203              :     void
     204              :     swap(
     205              :         request& t0,
     206              :         request& t1) noexcept
     207              :     {
     208              :         t0.swap(t1);
     209              :     }
     210              : };
     211              : 
     212              : } // http_proto
     213              : } // boost
     214              : 
     215              : #endif
        

Generated by: LCOV version 2.1