2#include <drogon/exports.h>
10enum class DROGON_EXPORT RateLimiterType
17inline RateLimiterType stringToRateLimiterType(
const std::string &type)
19 if (type ==
"fixedWindow" || type ==
"fixed_window")
20 return RateLimiterType::kFixedWindow;
21 else if (type ==
"slidingWindow" || type ==
"sliding_window")
22 return RateLimiterType::kSlidingWindow;
23 return RateLimiterType::kTokenBucket;
26using RateLimiterPtr = std::shared_ptr<RateLimiter>;
45 std::chrono::duration<double> timeUnit = std::chrono::seconds(60));
59 SafeRateLimiter(RateLimiterPtr limiter) : limiter_(limiter)
65 std::lock_guard<std::mutex> lock(mutex_);
66 return limiter_->isAllowed();
72 RateLimiterPtr limiter_;
This class is used to limit the number of requests per second.
Definition RateLimiter.h:33
static RateLimiterPtr newRateLimiter(RateLimiterType type, size_t capacity, std::chrono::duration< double > timeUnit=std::chrono::seconds(60))
Create a rate limiter.
virtual bool isAllowed()=0
Check if a request is allowed.
Definition RateLimiter.h:57
bool isAllowed() override
Check if a request is allowed.
Definition RateLimiter.h:63
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23