NetFlex  0.0.0
C++11 HTTP Server Library.
request_parser.hpp
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <deque>
26 #include <memory>
27 #include <string>
28 
29 #include <netflex/http/request.hpp>
30 #include <netflex/parsing/parser_iface.hpp>
31 #include <netflex/parsing/parsers_factory.hpp>
32 
33 namespace netflex {
34 
35 namespace parsing {
36 
42 
44 public:
46  request_parser(void);
48  ~request_parser(void) = default;
49 
51  request_parser(const request_parser&) = delete;
53  request_parser& operator=(const request_parser&) = delete;
54 
55 public:
62  request_parser& operator<<(const std::string& data);
63 
69  void operator>>(http::request& request);
70 
74  const http::request& get_front(void) const;
75 
79  void pop_front(void);
80 
85 
89  bool request_available(void) const;
90 
91 private:
97  bool build_request(void);
98 
99 private:
103  std::string m_buffer;
104 
108  http::request m_current_request;
109 
113  parsing_stage m_current_stage;
114 
118  std::unique_ptr<parser_iface> m_current_parser;
119 
123  std::deque<http::request> m_available_requests;
124 };
125 
126 } // namespace parsing
127 
128 } // namespace netflex
const http::request & get_currently_parsed_request(void) const
void operator>>(http::request &request)
request_parser(void)
default ctor
Definition: client.hpp:33
bool request_available(void) const
const http::request & get_front(void) const
Definition: request_parser.hpp:43
request_parser & operator<<(const std::string &data)
request_parser & operator=(const request_parser &)=delete
assignment operator
Definition: request.hpp:39
~request_parser(void)=default
default dtor