Proper error returning for rate limiting.

This commit is contained in:
stephb9959
2021-11-13 17:35:15 -08:00
parent 5b4dbb088f
commit 730ca7b292
4 changed files with 8 additions and 5 deletions

2
build
View File

@@ -1 +1 @@
74 76

View File

@@ -62,6 +62,7 @@ components:
- 7 # ACCESS_DENIED, - 7 # ACCESS_DENIED,
- 8 # INVALID_TOKEN - 8 # INVALID_TOKEN
- 9 # expired token - 9 # expired token
- 10 # rate limit exceeded
ErrorDetails: ErrorDetails:
type: string type: string
ErrorDescription: ErrorDescription:

View File

@@ -21,7 +21,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
Internal, false, true , RateLimit{.Interval=2000,.MaxCalls=10}) {} Internal, false, true , RateLimit{.Interval=1000,.MaxCalls=10}) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/oauth2/{token}","/api/v1/oauth2"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/oauth2/{token}","/api/v1/oauth2"}; };
void DoGet() final; void DoGet() final;
void DoPost() final; void DoPost() final;

View File

@@ -81,7 +81,8 @@ namespace OpenWifi {
INTERNAL_ERROR, INTERNAL_ERROR,
ACCESS_DENIED, ACCESS_DENIED,
INVALID_TOKEN, INVALID_TOKEN,
EXPIRED_TOKEN EXPIRED_TOKEN,
RATE_LIMIT_EXCEEDED
}; };
class AppServiceRegistry { class AppServiceRegistry {
@@ -1524,8 +1525,9 @@ namespace OpenWifi {
Request = &RequestIn; Request = &RequestIn;
Response = &ResponseIn; Response = &ResponseIn;
if(RateLimited_ && RESTAPI_RateLimiter()->IsRateLimited(RequestIn,MyRates_.Interval, MyRates_.MaxCalls)) if(RateLimited_ && RESTAPI_RateLimiter()->IsRateLimited(RequestIn,MyRates_.Interval, MyRates_.MaxCalls)) {
return; return UnAuthorized("Rate limit exceeded.",RATE_LIMIT_EXCEEDED);
}
if (!ContinueProcessing()) if (!ContinueProcessing())
return; return;