Skip to content

Commit

Permalink
Important rate limiter fix for ignoring paths
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Jul 31, 2024
1 parent 43464e5 commit 65bb482
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class RateLimiter(
@OptIn(ExperimentalContracts::class)
suspend inline fun gate(request: Request, auth: RequestAuth<*>?, ip: String, action: () -> Unit): RateLimitInfo? {
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) }
if (ignore(request)) return null
if (ignore(request)) {
action()
return null
}
val now = now()
val key = auth?.let { it.subject.name + "/" + it.rawId } ?: ip
val cacheKey = "rateLimiter-$rateLimiterId-$key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RateLimiterTest {
)
c.clear()

// With no artifical duration modification, many short requests are approximately equivalent to a few long ones
// With no artificial duration modification, many short requests are approximately equivalent to a few long ones
assertSuccessesForLimiter(
expected = 89,
limiter = RateLimiter(
Expand All @@ -113,7 +113,7 @@ class RateLimiterTest {
)
c.clear()

// With no artifical duration modification, many short requests are approximately equivalent to a few long ones
// With no artificial duration modification, many short requests are approximately equivalent to a few long ones
assertSuccessesForLimiter(
expected = 5,
limiter = RateLimiter(
Expand Down

0 comments on commit 65bb482

Please sign in to comment.