NetFlex  0.0.0
C++11 HTTP Server Library.
middleware_chain.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 <functional>
26 #include <list>
27 
28 #include <netflex/http/request.hpp>
29 #include <netflex/http/response.hpp>
30 
31 namespace netflex {
32 
33 namespace routing {
34 
36 class middleware_chain;
37 
42 typedef std::function<void(middleware_chain&, http::request&, http::response&)> middleware_t;
43 
49 public:
57  middleware_chain(const std::list<middleware_t>& middlewares, http::request& request, http::response& response);
58 
60  ~middleware_chain(void) = default;
61 
63  middleware_chain(const middleware_chain&) = default;
65  middleware_chain& operator=(const middleware_chain&) = default;
66 
67 public:
71  void proceed(void);
72 
73 private:
77  std::list<middleware_t> m_middlewares;
78 
82  http::request& m_request;
83 
87  http::response& m_response;
88 
92  std::list<middleware_t>::iterator m_current_middleware;
93 };
94 
95 } // namespace routing
96 
97 } // namespace netflex
middleware_chain(const std::list< middleware_t > &middlewares, http::request &request, http::response &response)
middleware_chain & operator=(const middleware_chain &)=default
assignment operator
Definition: middleware_chain.hpp:48
Definition: client.hpp:33
~middleware_chain(void)=default
default dtor
Definition: response.hpp:37
Definition: request.hpp:39