Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds an in-memory global HTTP rate limiter (per-platform and per-IP), integrates it into Fastify request handling, adds rate-limit entries to Changes
Sequence DiagramsequenceDiagram
participant Client
participant FastifyHook as Fastify Hook
participant RateLimiter as Rate Limiter
participant JWTDecoder as JWT Decoder
participant Server as Request Handler
Client->>FastifyHook: HTTP Request (with/without Bearer token)
FastifyHook->>FastifyHook: Extract token from Authorization header
FastifyHook->>RateLimiter: checkGlobalRateLimit(token, ip)
alt Token provided
RateLimiter->>JWTDecoder: Decode JWT & extract platform claim
JWTDecoder-->>RateLimiter: platform or null
alt Platform extracted
RateLimiter->>RateLimiter: Check platform request count
alt Platform limit exceeded
RateLimiter-->>FastifyHook: { allowed: false, retryAfterSeconds }
else Platform limit OK
RateLimiter->>RateLimiter: Check IP request count
alt IP limit exceeded
RateLimiter-->>FastifyHook: { allowed: false, retryAfterSeconds }
else Both limits OK
RateLimiter-->>FastifyHook: { allowed: true, retryAfterSeconds: 0 }
end
end
else Decoding failed
RateLimiter->>RateLimiter: Fall back to IP-only limiting
RateLimiter-->>FastifyHook: { allowed: boolean, retryAfterSeconds }
end
else No token
RateLimiter->>RateLimiter: Check IP request count
RateLimiter-->>FastifyHook: { allowed: boolean, retryAfterSeconds }
end
alt Allowed
FastifyHook->>Server: Continue request
Server-->>Client: Response
else Rate limit exceeded
FastifyHook-->>Client: HTTP 429 + Retry-After header
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description of change
Issue Number
Type of change
How the change has been tested
Change checklist
Summary by CodeRabbit
New Features
Performance & Stability