Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Retry-After data to request #165

Open
jsocol opened this issue Feb 20, 2019 · 1 comment
Open

Add Retry-After data to request #165

jsocol opened this issue Feb 20, 2019 · 1 comment

Comments

@jsocol
Copy link
Owner

jsocol commented Feb 20, 2019

Along with request.limited, add another attribute like request.limited_until or request.limited_expires that lets the view know how long until all relevant ratelimit windows expire.

A couple of examples:

@ratelimit(rate='10/m')  # this window expires in 22 seconds
def one_ratelimit(request):
    request.limited  # True
    request.limited_until  # 22

@ratelimit(rate='10/m')  # this window expires in 31 seconds
@ratelimit(rate='100/h')  # this limit has NOT been hit
def burst_limit(request):
    request.limited_until  # 31

@ratelimit(rate='10/m')  # this window expires in 19 seconds
@ratelimit(rate='100/h')  # this limit HAS been hit and expires in 1421 seconds
def true_limit(request):
    request.limited_until  # 1421

After #163 and #164, it should be relatively straightforward to replace the usage of is_ratelimited in @ratelimit with the more powerful get_usage_count, which will make this much easier.

I kind of prefer returning seconds so we don't have to deal with datetime math, which will probably be slightly more expensive, until/unless it's time to format the date. So limited_for or limited_seconds is probably a better name than limited_until. I like attempted keeping the name similar to limited, but request.retry_after could also work.

@mmway
Copy link

mmway commented Feb 25, 2021

this feature would be super to have. I think for user after blocking him/her it's most crucial information to have - "when I can try again?".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants