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 axum::extract::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.

Since ADR 0015 slice 2 (cratestack#877) this is a projection of build_rest_op_resolver — one lookup shared with idempotency, whose miss (OpAdmission::unresolved) is rate_limited_by_default: true, i.e. exactly the fail-closed answer above. For a router mounted with Router::nest, pass build_rest_op_resolver_with_prefix to super::RateLimitLayer::with_op_resolver instead.