Commit b24b90bc authored by Lukáš Lalinský's avatar Lukáš Lalinský

Merge branch 'live'

parents 18eaba97 f7e1d88d
Pipeline #20552 passed with stages
in 4 minutes and 12 seconds
......@@ -139,8 +139,7 @@ class ServiceUnavailable(WebServiceError):
class TooManyRequests(WebServiceError):
# status = 429
status = 503
status = 429
def __init__(self, rate):
message = 'rate limit (%f requests per second) exceeded, try again later' % rate
......
......@@ -112,22 +112,25 @@ class APIHandler(Handler):
def _rate_limit(self, user_ip, application_id):
# type: (str, Optional[int]) -> None
global_rate_limit = self.ctx.config.rate_limiter.global_rate_limit
if global_rate_limit is not None:
if self.rate_limiter.limit('global', '', global_rate_limit):
raise errors.TooManyRequests(global_rate_limit)
check_ip_rate_limit = True
if application_id is not None:
application_rate_limit = self.ctx.config.rate_limiter.applications.get(application_id)
if application_rate_limit is not None:
if self.rate_limiter.limit('app', str(application_id), application_rate_limit):
raise errors.TooManyRequests(application_rate_limit)
else:
return
check_ip_rate_limit = False
global_rate_limit = self.ctx.config.rate_limiter.global_rate_limit
if global_rate_limit is not None:
if self.rate_limiter.limit('global', '', global_rate_limit):
raise errors.TooManyRequests(global_rate_limit)
ip_rate_limit = self.ctx.config.rate_limiter.ips.get(user_ip, MAX_REQUESTS_PER_SECOND)
if self.rate_limiter.limit('ip', user_ip, ip_rate_limit):
raise errors.TooManyRequests(ip_rate_limit)
if check_ip_rate_limit:
ip_rate_limit = self.ctx.config.rate_limiter.ips.get(user_ip, MAX_REQUESTS_PER_SECOND)
if self.rate_limiter.limit('ip', user_ip, ip_rate_limit):
raise errors.TooManyRequests(ip_rate_limit)
def handle(self, req):
# type: (Request) -> Response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment