ResponseFilter

Trait ResponseFilter 

Source
pub trait ResponseFilter: Send + Sync {
    // Required method
    fn filter(&self, request: &mut ResponseContext<'_>) -> TiiResult<()>;
}
Expand description

Trait for a filter that may alter a Response after an endpoint has been called or a filter has aborted the request. Use cases: (Non-Exhaustive)

  • Adding Cors headers
  • Adding Various other headers
  • Logging of the response
  • “Rough” estimation of the time it takes for the endpoint to process things.

Required Methods§

Source

fn filter(&self, request: &mut ResponseContext<'_>) -> TiiResult<()>

Called with the request context adn response after the endpoint or error handler is called. Ok(…) -> proceed. Err -> Call error handler and proceed. (You cannot create a loop, a Response filter will only be called exactly once per RequestContext)

Implementors§

Source§

impl<F, R> ResponseFilter for F
where R: Into<TiiResult<()>>, F: Fn(&mut ResponseContext<'_>) -> R + Send + Sync,