GCC Code Coverage Report


Directory: libs/http_proto/
File: boost/http_proto/request_view.hpp
Date: 2024-07-25 21:11:05
Exec Total Coverage
Lines: 23 23 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_REQUEST_VIEW_HPP
11 #define BOOST_HTTP_PROTO_REQUEST_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 read-only reference to an HTTP request
21 */
22 class BOOST_SYMBOL_VISIBLE
23 request_view
24 : public message_view_base
25 {
26 friend class request;
27 friend class request_parser;
28
29 explicit
30 316 request_view(
31 detail::header const* ph) noexcept
32 316 : fields_view_base(ph)
33 {
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 316 times.
316 BOOST_ASSERT(ph_->kind ==
35 detail::kind::request);
36 316 }
37
38 public:
39 /** Constructor
40 */
41 4 request_view() noexcept
42 4 : fields_view_base(
43 detail::header::get_default(
44 4 detail::kind::request))
45 {
46 4 }
47
48 /** Constructor
49 */
50 1 request_view(
51 request_view const&) noexcept = default;
52
53 /** Assignment
54 */
55 request_view&
56 1 operator=(
57 request_view const&) noexcept = default;
58
59 //--------------------------------------------
60 //
61 // Observers
62 //
63 //--------------------------------------------
64
65 /** Return the method as an integral constant
66
67 If the method returned is equal to
68 @ref method::unknown, the method may
69 be obtained as a string instead, by
70 calling @ref method_text.
71 */
72 http_proto::method
73 55 method() const noexcept
74 {
75 55 return ph_->req.method;
76 };
77
78 /** Return the method as a string
79 */
80 core::string_view
81 55 method_text() const noexcept
82 {
83 110 return core::string_view(
84 55 ph_->cbuf,
85 55 ph_->req.method_len);
86 }
87
88 /** Return the request-target string
89 */
90 core::string_view
91 55 target_text() const noexcept
92 {
93 110 return core::string_view(
94 55 ph_->cbuf +
95 55 ph_->req.method_len + 1,
96 55 ph_->req.target_len);
97 }
98
99 /** Return the HTTP-version
100 */
101 http_proto::version
102 55 version() const noexcept
103 {
104 55 return ph_->version;
105 }
106
107 /** Swap this with another instance
108 */
109 void
110 swap(request_view& other) noexcept
111 {
112 auto ph = ph_;
113 ph_ = other.ph_;
114 ph_ = ph;
115 }
116
117 /** Swap two instances
118 */
119 // hidden friend
120 friend
121 void
122 swap(
123 request_view& t0,
124 request_view& t1) noexcept
125 {
126 t0.swap(t1);
127 }
128 };
129
130 } // http_proto
131 } // boost
132
133 #endif
134