Skip to main content

build_rest_ops_filter

Function build_rest_ops_filter 

Source
pub fn build_rest_ops_filter(
    routes: &'static [RouteTransportDescriptor],
) -> impl Fn(&Request<Body>) + Send + Sync
Expand description

Build a rate-limit filter function for REST schemas.

Returns a function that:

  • Reads the matched route pattern via MatchedPath (populated by axum under both Router::layer and Router::route_layer — see module docs).
  • Looks up the route (matched pattern + HTTP method) in the provided descriptors.
  • Returns false (exempt) if rate_limited_by_default is false.
  • Returns true (apply rate limit) if the route participates, or if lookup fails for any reason.

Fails closed: if MatchedPath is absent (the request matched no route — a 404) or the route isn’t found in routes (a schema/router mismatch), the request is rate-limited. This prevents accidental exemptions from missing data or misconfiguration.