Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ async def multiple():
return {"msg": "Hello World"}


@app.get("/unlimited", dependencies=[Depends(RateLimiter())])
async def unlimited():
return {"msg": "Hello World"}


@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
Expand Down
2 changes: 2 additions & 0 deletions fastapi_limiter/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(
self.callback = callback

async def _check(self, key):
if self.milliseconds <= 0:
return 0
redis = FastAPILimiter.redis
pexpire = await redis.evalsha(
FastAPILimiter.lua_sha, 1, key, str(self.times), str(self.milliseconds)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ def test_limiter_websockets():
data = ws.receive_text()
assert data == "Hello, world"
ws.close()


def test_unlimited():
with TestClient(app) as client:
response = client.get("/unlimited")
assert response.status_code == 200

response = client.get("/unlimited")
assert response.status_code == 200