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 #include <UT/UT_Regex.h>
21 #include <UT/UT_StringArray.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_WorkBuffer.h>
24 
25 class NET_HTTPRequest;
26 class NET_WebResponse;
27 
29 {
30 public:
31  NET_WebMiddleware() = default;
32  virtual ~NET_WebMiddleware() = default;
33 
34  NET_WebMiddleware(const NET_WebMiddleware&) = delete;
36 
37  virtual void processRequest(NET_HTTPRequest &req) const {}
38  virtual void processResponse(const NET_HTTPRequest &req, NET_WebResponse &resp) const {}
39 };
40 
41 // Compress response with GZIP
43 {
44 public:
45  void processResponse(const NET_HTTPRequest &req, NET_WebResponse &resp) const override;
46 };
47 
48 // Log Middleware
50 {
51 public:
52  NET_MessageMiddleware(bool process_request) :
53  myProcessRequest(process_request)
54  {}
55 
56  void processRequest(NET_HTTPRequest &req) const override;
57  void processResponse(const NET_HTTPRequest &req, NET_WebResponse &resp) const override;
58 
59 private:
60  bool myProcessRequest;
61 };
62 
63 // CORS Middleware
65 {
66 public:
67  void processResponse(const NET_HTTPRequest& req, NET_WebResponse &resp) const override;
68 };
69 
70 // Security Middleware
72 {
73 public:
75 
76  void processRequest(NET_HTTPRequest &req) const override;
77  void processResponse(const NET_HTTPRequest& req, NET_WebResponse& resp) const override;
78 
79  void redirect(bool redirect) { myRedirect = redirect; }
80  void redirectHost(const UT_StringHolder& redirect_host)
81  {
82  myRedirectHost = redirect_host;
83  }
84  void redirectExempt(const UT_StringArray& exempt)
85  {
86  myRedirectExempt.clear();
87  myRedirectExempt.setCapacity(exempt.size());
88  for (auto&& e : exempt)
89  myRedirectExempt.emplace_back(e);
90  }
91  void stsSeconds(int sts_seconds) { myStsSeconds = sts_seconds; }
92  void stsIncludeSubdomains(bool include_subdomains) { myStsIncludeSubdomains = include_subdomains; }
93  void stsPreload(bool preload) { myStsPreload = preload; }
94  void noSniff(bool no_sniff) { myContentNoSniff = no_sniff; }
95  void referrerPolicy(const UT_StringHolder& policy) { myReferrerPolicy = policy; }
97  {
98  UT_WorkBuffer wbuf;
99  for (auto&& item : policy)
100  {
101  if (!wbuf.isEmpty())
102  wbuf.append(',');
103  wbuf.append(item);
104  }
105  myReferrerPolicy = std::move(wbuf);
106  }
107  void crossOriginOpenerPolicy(const UT_StringHolder& cross_origin_opener_policy)
108  {
109  myCrossOriginOpenerPolicy = cross_origin_opener_policy;
110  }
111 
112 private:
113  bool matches(const UT_StringHolder& path, const UT_Array<UT_Regex>& items) const;
114 
115  bool myRedirect;
116  UT_Array<UT_Regex> myRedirectExempt;
117  UT_StringHolder myRedirectHost;
118  int myStsSeconds;
119  bool myStsIncludeSubdomains;
120  bool myStsPreload;
121  bool myContentNoSniff;
122  UT_StringHolder myReferrerPolicy;
123  UT_StringHolder myCrossOriginOpenerPolicy;
124 };
125 
126 #endif // __NET_WEBMIDDLEWARE_H__
127 
Response object used for responding to request in the server.
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
void redirect(bool redirect)
NET_MessageMiddleware(bool process_request)
exint size() const
Definition: UT_Array.h:646
void referrerPolicy(const UT_StringArray &policy)
#define NET_API
Definition: NET_API.h:9
void stsSeconds(int sts_seconds)
void redirectHost(const UT_StringHolder &redirect_host)
void redirectExempt(const UT_StringArray &exempt)
void crossOriginOpenerPolicy(const UT_StringHolder &cross_origin_opener_policy)
SYS_FORCE_INLINE bool isEmpty() const
void referrerPolicy(const UT_StringHolder &policy)
virtual void processResponse(const NET_HTTPRequest &req, NET_WebResponse &resp) const
void stsPreload(bool preload)
LeafData & operator=(const LeafData &)=delete
SYS_FORCE_INLINE void append(char character)
virtual void processRequest(NET_HTTPRequest &req) const
void noSniff(bool no_sniff)
void stsIncludeSubdomains(bool include_subdomains)