Skip to content

Commit 0575e10

Browse files
authored
Merge pull request #93 from PMDevSolutions/PAMulligan-patch-1
docs(worker): document checkRateLimit fixed-window behavior
2 parents 0d7c065 + 758b496 commit 0575e10

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

worker/src/rate-limit.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export interface RateLimitResult {
1414
limitType?: "minute" | "hour";
1515
}
1616

17+
/**
18+
* Fixed-window rate limiter backed by Workers KV. Tracks two independent
19+
* windows per IP (per-minute and per-hour) and rejects as soon as either
20+
* cap is reached, checking the tighter minute window first. On rejection,
21+
* `retryAfter` is set to the offending window's TTL so callers can emit an
22+
* accurate HTTP 429 `Retry-After` header. Counters auto-expire via KV TTL,
23+
* so no explicit reset/cleanup is required.
24+
*/
1725
export async function checkRateLimit(
1826
kv: KVNamespace,
1927
ip: string,

0 commit comments

Comments
 (0)