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

Generated by: LCOV version 1.15