LCOV - code coverage report
Current view: top level - libs/http_proto/src - response.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 65 65 100.0 %
Date: 2024-03-19 15:22:00 Functions: 9 16 56.2 %

          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_proto
       9             : //
      10             : 
      11             : #include <boost/http_proto/response.hpp>
      12             : #include <boost/http_proto/response_view.hpp>
      13             : #include <boost/http_proto/version.hpp>
      14             : 
      15             : #include <utility>
      16             : 
      17             : #include "detail/header_impl.hpp"
      18             : 
      19             : namespace boost {
      20             : namespace http_proto {
      21             : 
      22          33 : response::
      23          33 : response() noexcept
      24             :     : fields_view_base(
      25          33 :         &this->fields_base::h_)
      26             :     , message_base(
      27          33 :         detail::kind::response)
      28             : {
      29          33 : }
      30             : 
      31          88 : response::
      32             : response(
      33          88 :     core::string_view s)
      34             :     : fields_view_base(
      35          88 :         &this->fields_base::h_)
      36             :     , message_base(
      37          88 :         detail::kind::response, s)
      38             : {
      39          88 : }
      40             : 
      41           3 : response::
      42             : response(
      43           3 :     response&& other) noexcept
      44           3 :     : response()
      45             : {
      46           3 :     swap(other);
      47           3 : }
      48             : 
      49           2 : response::
      50             : response(
      51           2 :     response const& other)
      52             :     : fields_view_base(
      53           2 :         &this->fields_base::h_)
      54           2 :     , message_base(*other.ph_)
      55             : {
      56           2 : }
      57             : 
      58           2 : response::
      59             : response(
      60           2 :     response_view const& other)
      61             :     : fields_view_base(
      62           2 :         &this->fields_base::h_)
      63           2 :     , message_base(*other.ph_)
      64             : {
      65           2 : }
      66             : 
      67             : response&
      68           1 : response::
      69             : operator=(
      70             :     response&& other) noexcept
      71             : {
      72             :     response temp(
      73           1 :         std::move(other));
      74           1 :     temp.swap(*this);
      75           1 :     return *this;
      76             : }
      77             : 
      78           6 : response::
      79             : response(
      80           6 :     http_proto::status sc)
      81             :     : response(
      82           6 :         sc, http_proto::version::http_1_1)
      83             : {
      84           6 : }
      85             : 
      86          14 : response::
      87             : response(
      88             :     http_proto::status sc,
      89          14 :     http_proto::version v)
      90          14 :     : response()
      91             : {
      92          14 :     if( sc != h_.res.status ||
      93           4 :         v != h_.version)
      94          11 :         set_start_line(sc, v);
      95          14 : }
      96             : 
      97             : //------------------------------------------------
      98             : 
      99             : void
     100          19 : response::
     101             : set_impl(
     102             :     http_proto::status sc,
     103             :     unsigned short si,
     104             :     core::string_view rs,
     105             :     http_proto::version v)
     106             : {
     107             :     // measure and resize
     108          19 :     auto const vs = to_string(v);
     109             :     auto const n =
     110          19 :         vs.size() + 1 +
     111          19 :         3 + 1 +
     112          19 :         rs.size() +
     113          19 :         2;
     114             : 
     115          38 :     detail::prefix_op op(*this, n);
     116          19 :     auto dest = op.prefix_.data();
     117             : 
     118          19 :     h_.version = v;
     119          19 :     vs.copy(dest, vs.size());
     120          19 :     dest += vs.size();
     121          19 :     *dest++ = ' ';
     122             : 
     123          19 :     h_.res.status = sc;
     124          19 :     h_.res.status_int = si;
     125          19 :     dest[0] = '0' + ((h_.res.status_int / 100) % 10);
     126          19 :     dest[1] = '0' + ((h_.res.status_int /  10) % 10);
     127          19 :     dest[2] = '0' + ((h_.res.status_int /   1) % 10);
     128          19 :     dest[3] = ' ';
     129          19 :     dest += 4;
     130             : 
     131          19 :     rs.copy(dest, rs.size());
     132          19 :     dest += rs.size();
     133          19 :     dest[0] = '\r';
     134          19 :     dest[1] = '\n';
     135             : 
     136          19 :     h_.on_start_line();
     137          19 : }
     138             : 
     139             : } // http_proto
     140             : } // boost

Generated by: LCOV version 1.15