ResponseInterceptor

Trait ResponseInterceptor 

Source
pub trait ResponseInterceptor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn intercept(
        &self,
        response: Response<Full<Bytes>>,
    ) -> Response<Full<Bytes>>;
    fn clone_box(&self) -> Box<dyn ResponseInterceptor>;
}
Expand description

Trait for intercepting and modifying responses after handlers complete.

Response interceptors are executed in reverse registration order. Each interceptor receives the response, can modify it, and returns the (potentially modified) response for the previous interceptor or client.

§Example

use rustapi_core::interceptor::ResponseInterceptor;
use rustapi_core::Response;

struct AddCorsHeaders;

impl ResponseInterceptor for AddCorsHeaders {
    fn intercept(&self, mut res: Response) -> Response {
        res.headers_mut().insert(
            "Access-Control-Allow-Origin",
            "*".parse().unwrap()
        );
        res
    }
}

Required Methods§

Source

fn intercept(&self, response: Response<Full<Bytes>>) -> Response<Full<Bytes>>

Intercept and optionally modify the response.

The returned response will be passed to the previous interceptor or client.

Source

fn clone_box(&self) -> Box<dyn ResponseInterceptor>

Clone this interceptor into a boxed trait object.

Implementors§