Module filter

Source
Expand description

Conditionally dispatch requests to the inner service based on the result of a predicate.

Unlike filter mod in tower, this let you return a custom response to user when the request is rejected.

§Example

     Router::new()
         .route("/get", get(|| async { "get works" }))
         .layer(FilterExLayer::new(|request: Request<Body>| {
             if let Some(_auth) = request.headers().typed_get::<Authorization<Basic>>() {
                 // TODO: do something
                 Ok(request)
            } else {
                Err(StatusCode::UNAUTHORIZED.into_response())
            }
         }));

Structs§

AsyncFilterEx
Conditionally dispatch requests to the inner service based on an asynchronous predicate
AsyncFilterExLayer
Conditionally dispatch requests to the inner service based on an asynchronous predicate
FilterEx
Conditionally dispatch requests to the inner service based on a predicate.
FilterExLayer
Conditionally dispatch requests to the inner service based on a synchronous predicate.

Traits§

AsyncPredicate
Checks a request asynchronously
Predicate
Checks a request synchronously

Functions§

drain_body