LCOV - code coverage report
Current view: top level - libs/http_proto/src - response.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 75 75 100.0 %
Date: 2024-04-23 10:22:13 Functions: 11 20 55.0 %

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

Generated by: LCOV version 1.15