LCOV - code coverage report
Current view: top level - http_proto/impl - request.ipp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 63 86 73.3 %
Date: 2023-01-15 07:18:31 Functions: 6 11 54.5 %

          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_IMPL_REQUEST_IPP
      11             : #define BOOST_HTTP_PROTO_IMPL_REQUEST_IPP
      12             : 
      13             : #include <boost/http_proto/request.hpp>
      14             : #include <boost/http_proto/request_view.hpp>
      15             : #include <boost/http_proto/detail/copied_strings.hpp>
      16             : #include <boost/http_proto/detail/number_string.hpp>
      17             : #include <utility>
      18             : 
      19             : namespace boost {
      20             : namespace http_proto {
      21             : 
      22         199 : request::
      23         199 : request() noexcept
      24             :     : fields_view_base(
      25         199 :         &this->fields_base::h_)
      26             :     , message_base(
      27         199 :         detail::kind::request)
      28             : {
      29         199 : }
      30             : 
      31          22 : request::
      32             : request(
      33          22 :     request&& other) noexcept
      34             :     : fields_view_base(
      35          22 :         &this->fields_base::h_)
      36             :     , message_base(
      37          22 :         detail::kind::request)
      38             : {
      39          22 :     swap(other);
      40          22 : }
      41             : 
      42           2 : request::
      43             : request(
      44           2 :     request const& other)
      45             :     : fields_view_base(
      46           2 :         &this->fields_base::h_)
      47           2 :     , message_base(*other.ph_)
      48             : {
      49           2 : }
      50             : 
      51           0 : request::
      52             : request(
      53           0 :     request_view const& other)
      54             :     : fields_view_base(
      55           0 :         &this->fields_base::h_)
      56           0 :     , message_base(*other.ph_)
      57             : {
      58           0 : }
      59             : 
      60             : request&
      61          20 : request::
      62             : operator=(
      63             :     request&& other) noexcept
      64             : {
      65             :     request temp(
      66          20 :         std::move(other));
      67          20 :     temp.swap(*this);
      68          20 :     return *this;
      69             : }
      70             : 
      71             : //------------------------------------------------
      72             : 
      73             : void
      74           2 : request::
      75             : set_expect_100_continue(bool b)
      76             : {
      77           2 :     if(h_.md.expect.count == 0)
      78             :     {
      79           1 :         BOOST_ASSERT(
      80             :             ! h_.md.expect.ec.failed());
      81           1 :         BOOST_ASSERT(
      82             :             ! h_.md.expect.is_100_continue);
      83           1 :         if(b)
      84           1 :             return append(
      85             :                 field::expect,
      86           1 :                 "100-continue");
      87           0 :         return;
      88             :     }
      89             : 
      90           1 :     if(h_.md.expect.count == 1)
      91             :     {
      92           1 :         if(b)
      93             :         {
      94           0 :             if(! h_.md.expect.ec.failed())
      95             :             {
      96           0 :                 BOOST_ASSERT(
      97             :                     h_.md.expect.is_100_continue);
      98           0 :                 return;
      99             :             }
     100           0 :             BOOST_ASSERT(
     101             :                 ! h_.md.expect.is_100_continue);
     102           0 :             auto it = find(field::expect);
     103           0 :             BOOST_ASSERT(it != end());
     104           0 :             erase(it);
     105           0 :             return;
     106             :         }
     107             : 
     108           1 :         auto it = find(field::expect);
     109           1 :         BOOST_ASSERT(it != end());
     110           1 :         erase(it);
     111           1 :         return;
     112             :     }
     113             : 
     114           0 :     if(b)
     115             :     {
     116           0 :         if(! h_.md.expect.ec.failed())
     117             :         {
     118             :             // remove all but one
     119           0 :             raw_erase_n(
     120             :                 field::expect,
     121           0 :                 h_.md.expect.count - 1);
     122           0 :             return;
     123             :         }
     124             : 
     125           0 :         erase(field::expect);
     126           0 :         return append(
     127             :             field::expect,
     128           0 :             "100-continue");
     129             :     }
     130             : 
     131           0 :     erase(field::expect);
     132             : }
     133             : 
     134             : //------------------------------------------------
     135             : 
     136             : void
     137         192 : request::
     138             : set_impl(
     139             :     http_proto::method m,
     140             :     string_view ms,
     141             :     string_view t,
     142             :     http_proto::version v)
     143             : {
     144             :     detail::copied_strings cs(
     145         384 :         this->buffer());
     146         192 :     ms = cs.maybe_copy(ms);
     147         192 :     t = cs.maybe_copy(t);
     148             : 
     149             :     auto const vs =
     150         192 :         to_string(v);
     151             :     auto const n =
     152         192 :         ms.size() + 1 +
     153         192 :         t.size() + 1 +
     154         192 :         vs.size() + 2;
     155         192 :     auto dest = set_prefix_impl(n);
     156         191 :     std::memcpy(
     157             :         dest,
     158         191 :         ms.data(),
     159             :         ms.size());
     160         191 :     dest += ms.size();
     161         191 :     *dest++ = ' ';
     162         191 :     std::memcpy(
     163             :         dest,
     164         191 :         t.data(),
     165             :         t.size());
     166         191 :     dest += t.size();
     167         191 :     *dest++ = ' ';
     168         191 :     std::memcpy(
     169             :         dest,
     170         191 :         vs.data(),
     171             :         vs.size());
     172         191 :     dest += vs.size();
     173         191 :     *dest++ = '\r';
     174         191 :     *dest++ = '\n';
     175             : 
     176         191 :     h_.version = v;
     177         191 :     h_.req.method = m;
     178         191 :     h_.req.method_len =
     179         191 :         static_cast<off_t>(ms.size());
     180         191 :     h_.req.target_len =
     181         191 :         static_cast<off_t>(t.size());
     182             : 
     183         191 :     h_.on_start_line();
     184         191 : }
     185             : 
     186             : } // http_proto
     187             : } // boost
     188             : 
     189             : #endif

Generated by: LCOV version 1.15