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_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 request_view
23 : : public message_view_base
24 : {
25 : friend class request_base;
26 : friend class request_parser;
27 :
28 : explicit
29 318 : request_view(
30 : detail::header const* ph) noexcept
31 318 : : fields_view_base(ph)
32 : {
33 318 : BOOST_ASSERT(ph_->kind ==
34 : detail::kind::request);
35 318 : }
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 1 : 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 55 : method() const noexcept
73 : {
74 55 : return ph_->req.method;
75 : };
76 :
77 : /** Return the method as a string
78 : */
79 : core::string_view
80 55 : method_text() const noexcept
81 : {
82 110 : return core::string_view(
83 55 : ph_->cbuf,
84 55 : ph_->req.method_len);
85 : }
86 :
87 : /** Return the request-target string
88 : */
89 : core::string_view
90 55 : target() const noexcept
91 : {
92 110 : return core::string_view(
93 55 : ph_->cbuf +
94 55 : ph_->req.method_len + 1,
95 55 : ph_->req.target_len);
96 : }
97 :
98 : /** Return the HTTP-version
99 : */
100 : http_proto::version
101 55 : version() const noexcept
102 : {
103 55 : 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
|