Module policy
Expand description
Limit policies for super::Limit
define how requests are handled when the limit is reached
for a given request.
Option
can be used to disable a limit policy for some scenarios
while enabling it for others.
§Policy Maps
A policy which applies a Policy
based on a Matcher
.
These can be made by using a Vec<(Matcher
, Policy
)>.
To avoid cloning you best use an Arc<…> around the most outer vec.
The first matching policy is used.
If no policy matches, the request is allowed to proceed as well.
If you want to enforce a default policy, you can add a policy with a Matcher
that always matches,
such as the bool true
.
Note that the Matcher
s will not receive the mutable Extensions
,
as polices are not intended to keep track of what is matched on.
It is this policy that you want to use in case you want to rate limit only
external sockets or you want to rate limit specific domains/paths only for http requests.
See the [http_rate_limit.rs
] example for a use case.
Structs§
- The default
ConcurrentTracker
that uses a counter to track the concurrent requests. - A
Policy
that limits the number of concurrent requests. - request aborted due to exhausted concurrency limit
- The full result of a limit policy.
- An unlimited policy that allows all requests to proceed.
Enums§
- The output part of a limit policy.
Traits§
- The tracker trait that can be implemented to provide custom concurrent request tracking.
- A limit
Policy
is used to determine whether a request is allowed to proceed, and if not, how to handle it.