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