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

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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_RESPONSE_VIEW_HPP
      11              : #define BOOST_HTTP_PROTO_RESPONSE_VIEW_HPP
      12              : 
      13              : #include <boost/http_proto/detail/config.hpp>
      14              : #include <boost/http_proto/message_view_base.hpp>
      15              : #include <boost/core/detail/string_view.hpp>
      16              : 
      17              : namespace boost {
      18              : namespace http_proto {
      19              : 
      20              : /** A reference to an HTTP response header
      21              : */
      22              : class response_view
      23              :     : public message_view_base
      24              : {
      25              :     friend class response_base;
      26              :     friend class response_parser;
      27              : 
      28              :     explicit
      29           83 :     response_view(
      30              :         detail::header const* ph) noexcept
      31           83 :         : fields_view_base(ph)
      32              :     {
      33           83 :         BOOST_ASSERT(ph_->kind ==
      34              :             detail::kind::response);
      35           83 :     }
      36              : 
      37              : public:
      38              :     /** Constructor
      39              :     */
      40            4 :     response_view() noexcept
      41            4 :         : fields_view_base(
      42              :             detail::header::get_default(
      43            4 :                 detail::kind::response))
      44              :     {
      45            4 :     }
      46              : 
      47              :     /** Constructor
      48              :     */
      49            1 :     response_view(
      50              :         response_view const&) noexcept = default;
      51              : 
      52              :     /** Assignment
      53              :     */
      54              :     response_view&
      55            1 :     operator=(
      56              :         response_view const&) noexcept = default;
      57              : 
      58              :     //--------------------------------------------
      59              :     //
      60              :     // Observers
      61              :     //
      62              :     //--------------------------------------------
      63              : 
      64              :     /** Return the reason string
      65              : 
      66              :         This field is obsolete in HTTP/1
      67              :         and should only be used for display
      68              :         purposes.
      69              :     */
      70              :     core::string_view
      71            4 :     reason() const noexcept
      72              :     {
      73            8 :         return core::string_view(
      74            4 :             ph_->cbuf + 13,
      75            4 :             ph_->prefix - 15);
      76              :     }
      77              : 
      78              :     /** Return the status code
      79              :     */
      80              :     http_proto::status
      81            4 :     status() const noexcept
      82              :     {
      83            4 :         return ph_->res.status;
      84              :     }
      85              : 
      86              :     /** Return the status code integer
      87              :     */
      88              :     unsigned short
      89            4 :     status_int() const noexcept
      90              :     {
      91            4 :         return ph_->res.status_int;
      92              :     }
      93              : 
      94              :     /** Return the HTTP-version
      95              :     */
      96              :     http_proto::version
      97            4 :     version() const noexcept
      98              :     {
      99            4 :         return ph_->version;
     100              :     }
     101              : 
     102              :     /** Swap this with another instance
     103              :     */
     104              :     void
     105              :     swap(response_view& other) noexcept
     106              :     {
     107              :         auto ph = ph_;
     108              :         ph_ = other.ph_;
     109              :         ph_ = ph;
     110              :     }
     111              : 
     112              :     /** Swap two instances
     113              :     */
     114              :     // hidden friend
     115              :     friend
     116              :     void
     117              :     swap(
     118              :         response_view& t0,
     119              :         response_view& t1) noexcept
     120              :     {
     121              :         t0.swap(t1);
     122              :     }
     123              : };
     124              : 
     125              : } // http_proto
     126              : } // boost
     127              : 
     128              : #endif
        

Generated by: LCOV version 2.1