LCOV - code coverage report
Current view: top level - http_proto - response_view.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 6 10 60.0 %
Date: 2023-01-15 07:18:31 Functions: 3 4 75.0 %

          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             : 
      16             : namespace boost {
      17             : namespace http_proto {
      18             : 
      19             : /** A reference to an HTTP response header
      20             : */
      21             : class BOOST_SYMBOL_VISIBLE
      22           1 :     response_view
      23             :     : public message_view_base
      24             : {
      25             :     friend class response;
      26             :     friend class response_parser;
      27             : 
      28             :     explicit
      29           0 :     response_view(
      30             :         detail::header const* ph) noexcept
      31           0 :         : fields_view_base(ph)
      32             :     {
      33           0 :         BOOST_ASSERT(ph_->kind ==
      34             :             detail::kind::response);
      35           0 :     }
      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             :     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             :     string_view
      71             :     reason() const noexcept
      72             :     {
      73             :         return string_view(
      74             :             ph_->cbuf + 13,
      75             :             ph_->prefix - 15);
      76             :     }
      77             : 
      78             :     /** Return the status code
      79             :     */
      80             :     http_proto::status
      81             :     status() const noexcept
      82             :     {
      83             :         return ph_->res.status;
      84             :     }
      85             : 
      86             :     /** Return the status code integer
      87             :     */
      88             :     unsigned short
      89             :     status_int() const noexcept
      90             :     {
      91             :         return ph_->res.status_int;
      92             :     }
      93             : 
      94             :     /** Return the HTTP-version
      95             :     */
      96             :     http_proto::version
      97             :     version() const noexcept
      98             :     {
      99             :         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 1.15