def enforce_api_rate_limit(action, limit_in_window):
"""Enforces API rate limit.
Args:
action: Action name.
limit_in_window: Maximum number of requests of this action in a window.
Raises:
bottle.HTTPError: If the rate limit is exceeded.
"""
if (FLAGS.enable_load_test_hacks and
bottle.request.headers.get('X-Load-Test', '') == 'yes'):
return
if get_current_user()['organizer']:
return
username = get_current_username()
if (model.record_last_api_access_time(username) <
FLAGS.api_rate_limit_request_interval):
bottle.abort(429, 'Rate limit exceeded (per-second limit).')
count = model.increment_api_rate_limit_counter(username, action)
if count > limit_in_window:
bottle.abort(429, 'Rate limit exceeded (per-hour limit).')
# http://flask.pocoo.org/snippets/44/
评论列表
文章目录