class
Kemal::BasicAuth::RateLimiter
- Kemal::BasicAuth::RateLimiter
- Reference
- Object
Overview
Simple in-memory sliding-window rate limiter for failed authentication attempts. Tracks failures per key (typically the remote address) and treats a key as "limited" once the configured threshold is reached within the window.
Thread-safe via an internal Mutex. Memory grows with the number of
distinct keys; #purge_expired may be called periodically to drop
entries whose attempts have all aged out.
limiter = Kemal::BasicAuth::RateLimiter.new(max_attempts: 5, window: 1.minute)
Defined in:
kemal-basic-auth/rate_limiter.crConstant Summary
-
DEFAULT_MAX_ATTEMPTS =
5 -
DEFAULT_WINDOW =
1.minute
Constructors
Instance Method Summary
-
#limited?(key : String) : Bool
Returns true if the key has reached or exceeded
#max_attemptswithin the active window. - #max_attempts : Int32
-
#purge_expired : Nil
Drops entries whose attempts have all aged out of the window.
-
#record_failure(key : String) : Int32
Records a failed attempt for the given key and returns the number of attempts within the active window after this one was recorded.
-
#reset(key : String) : Nil
Clears any recorded failures for the key (e.g.
- #window : Time::Span
Constructor Detail
Instance Method Detail
Returns true if the key has reached or exceeded #max_attempts within
the active window.
Records a failed attempt for the given key and returns the number of attempts within the active window after this one was recorded.
Clears any recorded failures for the key (e.g. after a successful login).