long2ice / fastapi-limiter

A request rate limiter for fastapi
https://github.com/long2ice/fastapi-limiter
Apache License 2.0
487 stars 53 forks source link

Any way to reset limit under source function? #21

Open kirillzhosul opened 2 years ago

kirillzhosul commented 2 years ago

Hello! Is there any way to reset (call block) limit inside source code of the function (e.g: Set limit once there is some condition under route)?

kirillzhosul commented 2 years ago

Tried to research situation. Writen some additional method to the Dependency, allows to call it not from depends.

async def check(self, request: Request, response: Response | None = None):
    return await self.__call__(request, response)

Example of using inside router:

await RateLimiter(seconds=1).check(req)

This is maybe a bit messy, but I not found solution for now. (Response inside callback / call is not used by default callback, and I dont found any need for it).