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