GCC Code Coverage Report


Directory: libs/http_proto/
File: boost/http_proto/response_view.hpp
Date: 2024-04-23 20:44:52
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 8 8 100.0%
Branches: 1 2 50.0%

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