Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature request: Attach information about rate-limit violations to request object for use in custom middleware #291

Open
ThomasAitken opened this issue Jul 3, 2023 · 0 comments

Comments

@ThomasAitken
Copy link

i.e. something like a change to core.is_ratelimited as follows:

def is_ratelimited(request, group=None, fn=None, key=None, rate=None, method=ratelimit.ALL, increment=False):
    usage = ratelimit.core.get_usage(request, group, fn, key, rate, method, increment)
    if usage is None:
        return False

    # patching begins... attaching the key data to the request object
    if usage["should_limit"]:
        request.django_ratelimit_data = {
            "group": group,
            "fn_name": fn.__name__ if fn is not None else None,
            "count": usage["count"],
            "limit": usage["limit"],
        }
    return usage["should_limit"]

Is there any reason why you didn't do this? It would help a lot for logging and figuring out what's actually going on with users.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant