HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_WebMiddleware.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_WebMiddleware.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __NET_WEBMIDDLEWARE_H__
13 #define __NET_WEBMIDDLEWARE_H__
14 
15 #include "NET_API.h"
16 
17 #include "NET_HTTPDefines.h"
18 
19 #include <UT/UT_Array.h>
20 
21 #include <functional>
22 
23 class NET_HTTPRequest;
24 class NET_WebResponse;
25 
26 class NET_API NET_WebMiddleware
27 {
28 public:
29  using RequestMiddleware = std::function<void(NET_HTTPRequest &)>;
30  using ResponseMiddleware =
31  std::function<void(NET_HTTPRequest &, NET_WebResponse &)>;
32 
33  void add(RequestMiddleware mw) { myRequestMiddleware.emplace_back(mw); }
34  void add(ResponseMiddleware mw) { myResponseMiddleware.emplace_back(mw); }
35 
36  void processRequest(NET_HTTPRequest &req);
37  void processResponse(NET_HTTPRequest &req, NET_WebResponse &resp);
38 
39 private:
40  UT_Array<RequestMiddleware> myRequestMiddleware;
41  UT_Array<ResponseMiddleware> myResponseMiddleware;
42 };
43 
44 // Compress response with GZIP
45 class NET_API NET_GZipMiddleware
46 {
47 public:
48  static void responseMiddleware(NET_HTTPRequest &req, NET_WebResponse &resp);
49 };
50 
51 // Log Middleware
52 class NET_API NET_MessageMiddleware
53 {
54 public:
55  static void requestMiddleware(NET_HTTPRequest &req);
56  static void responseMiddleware(NET_HTTPRequest &req, NET_WebResponse &resp);
57 };
58 
59 #endif // __NET_WEBMIDDLEWARE_H__
60 
std::function< void(NET_HTTPRequest &)> RequestMiddleware
Response object used for responding to request in the server.
void add(RequestMiddleware mw)
void add(ResponseMiddleware mw)
std::function< void(NET_HTTPRequest &, NET_WebResponse &)> ResponseMiddleware