Middleware that provides flow control functionality.
RateIssuer
provides an abstraction for identifying visitor identity keys. RemoteIpIssuer
is an implementation that identifies visitors based on their request IP address. The key does not have to be a string type; any type satisfying the Hash + Eq + Send + Sync + 'static
constraints can be used as a key.
RateGuard
provides an abstraction for flow control algorithms. It comes with two built-in implementations: fixed window (FixedGuard
) and sliding window (SlidingGuard
).
RateStore
provides an abstraction for data storage and retrieval. MokaStore
is a built-in in-memory cache implementation based on moka
. You can also define your own custom implementations.
RateLimiter
is a struct that implements Handler
. It contains a skipper
field, which can be used to specify requests that should bypass rate limiting. By default, it uses none_skipper
, which does not skip any requests.
QuotaGetter
provides an abstraction for retrieving quotas. It can fetch a quota object based on the visitor's Key
. This means user quota information can be configured in a database, allowing for dynamic changes and retrieval.
Example Code