HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_RateLimit.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_RateLimit.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __NET_RATELIMIT_H__
14 #define __NET_RATELIMIT_H__
15 
16 #include "NET_API.h"
17 
19 
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_Function.h>
22 #include <UT/UT_StringArray.h>
23 
24 class NET_HTTPRequest;
25 
26 enum class NET_HTTPRateKey
27 {
28  RATE_IP,
30 };
31 
33 {
34 public:
35  using func_t = UT_Function<
36  std::pair<int, int>(const UT_StringRef&, const NET_HTTPRequest&)>;
37 
38  NET_HTTPRate() = default;
39 
40  NET_HTTPRate(int count, int seconds) :
41  myCount(count),
42  myPeriodS(seconds)
43  {}
44 
45  explicit NET_HTTPRate(func_t&& f) : myCount(0), myPeriodS(0), myCustom(f) {}
46 
47  int myCount = 0;
48  int myPeriodS = 0;
50 };
51 
53 {
54 public:
55  int myCount = 0;
56  int myLimit = 0;
57  bool myShouldLimit = false;
58  int myTimeLeft = -1;
59 };
60 
62  const NET_HTTPRequest& request,
63  const UT_StringRef& group,
64  NET_HTTPRateKey key,
65  const NET_HTTPRate& rate,
66  const UT_StringArray& methods = UT_StringArray(),
67  bool increment = false);
68 
70  const NET_HTTPRequest& request,
71  const UT_StringRef& group,
72  NET_HTTPRateKey key,
73  const NET_HTTPRate& rate,
74  const UT_StringArray& methods,
75  bool increment);
76 
78 {
79 public:
80  void settings(
81  const UT_StringHolder& group,
82  NET_HTTPRateKey key,
83  const NET_HTTPRate& rate,
84  const std::initializer_list<UT_StringHolder>& methods);
85 
86  void handle(NET_HTTPRequest& req) override;
87 
88 private:
89  UT_StringHolder myGroup;
90  NET_HTTPRateKey myKey;
91  NET_HTTPRate myRate;
92  UT_StringArray myMethods;
93 };
94 
95 #endif // __NET_RATELIMIT_H__
#define NET_API
Definition: NET_API.h:9
GLfloat f
Definition: glcorearb.h:1926
void settings(const UT_StringHolder &group, NET_HTTPRateKey key, const NET_HTTPRate &rate, const std::initializer_list< UT_StringHolder > &methods)
NET_API NET_HTTPRateLimit NETgetRateUsage(const NET_HTTPRequest &request, const UT_StringRef &group, NET_HTTPRateKey key, const NET_HTTPRate &rate, const UT_StringArray &methods, bool increment)
UT_Function< std::pair< int, int >(const UT_StringRef &, const NET_HTTPRequest &)> func_t
Definition: NET_RateLimit.h:36
NET_HTTPRate(func_t &&f)
Definition: NET_RateLimit.h:45
NET_HTTPRate(int count, int seconds)
Definition: NET_RateLimit.h:40
std::function< T > UT_Function
Definition: UT_Function.h:37
NET_API bool NETisRateLimited(const NET_HTTPRequest &request, const UT_StringRef &group, NET_HTTPRateKey key, const NET_HTTPRate &rate, const UT_StringArray &methods=UT_StringArray(), bool increment=false)
NET_HTTPRateKey
Definition: NET_RateLimit.h:26
void handle(NET_HTTPRequest &req) override
GLint GLsizei count
Definition: glcorearb.h:405
func_t myCustom
Definition: NET_RateLimit.h:49