From 08b7370dbc65b9c12d2f2ff6503fec2dfebb2aa7 Mon Sep 17 00:00:00 2001 From: sangeethailango Date: Mon, 22 Dec 2025 16:05:08 +0530 Subject: [PATCH] chore: set header --- apps/api/plane/api/rate_limit.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/api/plane/api/rate_limit.py b/apps/api/plane/api/rate_limit.py index 1cc99bfd48..299a13118a 100644 --- a/apps/api/plane/api/rate_limit.py +++ b/apps/api/plane/api/rate_limit.py @@ -106,7 +106,21 @@ class WorkspaceTokenRateThrottle(SimpleRateThrottle): token = APIToken.objects.filter(token=api_key).only("allowed_rate_limit").first() if token and token.allowed_rate_limit: self.rate = token.allowed_rate_limit - # Must re-parse to update num_requests and duration + self.num_requests, self.duration = self.parse_rate(self.rate) - return super().allow_request(request, view) + allowed = super().allow_request(request, view) + + if allowed: + now = self.timer() + history = self.cache.get(self.key, []) + + while history and history[-1] <= now - self.duration: + history.pop() + + available = self.num_requests - len(history) + + request.META["X-RateLimit-Remaining"] = max(0, available) + request.META["X-RateLimit-Reset"] = int(now + self.duration) + + return allowed