libs/http/include/boost/http/request_parser.hpp

100.0% Lines (6/6) 100.0% Functions (4/4) -% Branches (0/0)
libs/http/include/boost/http/request_parser.hpp
Line Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2025 Mohammad Nejati
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/cppalliance/http
9 //
10
11 #ifndef BOOST_HTTP_REQUEST_PARSER_HPP
12 #define BOOST_HTTP_REQUEST_PARSER_HPP
13
14 #include <boost/http/detail/config.hpp>
15 #include <boost/http/error.hpp>
16 #include <boost/http/method.hpp>
17 #include <boost/http/parser.hpp>
18 #include <boost/http/static_request.hpp>
19
20 #include <memory>
21
22 namespace boost {
23 namespace http {
24
25 /// @copydoc parser
26 /// @brief A parser for HTTP/1 requests.
27 /// @see @ref response_parser.
28 class request_parser
29 : public parser
30 {
31 public:
32 /** Destructor.
33
34 Any views or buffers obtained from this
35 parser become invalid.
36 */
37 1025 ~request_parser() = default;
38
39 /** Default constructor.
40
41 Constructs a parser with no allocated state.
42 The parser must be assigned from a valid
43 parser before use.
44
45 @par Postconditions
46 The parser has no allocated state.
47 */
48 6 request_parser() = default;
49
50 /** Constructor.
51
52 Constructs a parser with the provided configuration.
53
54 The parser will allocate the required space on
55 startup based on the config parameters, and will
56 not perform any further allocations.
57
58 @par Example
59 @code
60 auto cfg = make_parser_config(parser_config{true});
61 request_parser pr(cfg);
62 @endcode
63
64 @par Complexity
65 Constant.
66
67 @par Exception Safety
68 Calls to allocate may throw.
69
70 @param cfg Shared pointer to parser configuration.
71
72 @see @ref make_parser_config, @ref parser_config.
73 */
74 BOOST_HTTP_DECL
75 explicit
76 request_parser(
77 std::shared_ptr<parser_config_impl const> cfg);
78
79 /** Constructor.
80
81 The states of `other` are transferred
82 to the newly constructed object,
83 including the allocated buffer.
84 After construction, the only valid
85 operations on the moved-from object
86 are destruction and assignment.
87
88 Buffer sequences previously obtained
89 using @ref prepare or @ref pull_body
90 remain valid.
91
92 @par Complexity
93 Constant.
94
95 @param other The parser to move from.
96 */
97 2 request_parser(
98 request_parser&& other) noexcept = default;
99
100 /** Assignment.
101 The states of `other` are transferred
102 to this object, including the allocated
103 buffer.
104 After assignment, the only valid
105 operations on the moved-from object
106 are destruction and assignment.
107 Buffer sequences previously obtained
108 using @ref prepare or @ref pull_body
109 remain valid.
110 @par Complexity
111 Constant.
112 @param other The parser to move from.
113 */
114 request_parser&
115 2 operator=(request_parser&& other) noexcept
116 {
117 2 assign(std::move(other));
118 2 return *this;
119 }
120
121 /** Return a reference to the parsed request headers.
122
123 The returned reference remains valid until:
124 @li @ref start is called
125 @li @ref reset is called
126 @li The parser instance is destroyed
127
128 @par Preconditions
129 @code
130 this->got_header() == true
131 @endcode
132
133 @par Exception Safety
134 Strong guarantee.
135
136 @see
137 @ref got_header.
138 */
139 BOOST_HTTP_DECL
140 static_request const&
141 get() const;
142 };
143
144 } // http
145 } // boost
146
147 #endif
148