Skip to main content

HttpHandler

Trait HttpHandler 

Source
pub trait HttpHandler:
    Clone
    + Send
    + Sync
    + 'static {
    // Provided methods
    fn handle_request(
        &mut self,
        _ctx: &HttpContext,
        req: Request<Body>,
    ) -> impl Future<Output = RequestOrResponse> + Send { ... }
    fn handle_response(
        &mut self,
        _ctx: &HttpContext,
        res: Response<Body>,
    ) -> impl Future<Output = Response<Body>> + Send { ... }
    fn handle_error(
        &mut self,
        _ctx: &HttpContext,
        err: Error,
    ) -> impl Future<Output = Response<Body>> + Send { ... }
    fn should_intercept(
        &mut self,
        _ctx: &HttpContext,
        _req: &Request<Body>,
    ) -> impl Future<Output = bool> + Send { ... }
}
Expand description

Handler for HTTP requests and responses.

Each request/response pair is passed to the same instance of the handler.

Provided Methods§

Source

fn handle_request( &mut self, _ctx: &HttpContext, req: Request<Body>, ) -> impl Future<Output = RequestOrResponse> + Send

This handler will be called for each HTTP request. It can either return a modified request, or a response. If a request is returned, it will be sent to the upstream server. If a response is returned, it will be sent to the client.

Source

fn handle_response( &mut self, _ctx: &HttpContext, res: Response<Body>, ) -> impl Future<Output = Response<Body>> + Send

This handler will be called for each HTTP response. It can modify a response before it is forwarded to the client.

Source

fn handle_error( &mut self, _ctx: &HttpContext, err: Error, ) -> impl Future<Output = Response<Body>> + Send

This handler will be called if a proxy request fails. Default response is a 502 Bad Gateway.

Source

fn should_intercept( &mut self, _ctx: &HttpContext, _req: &Request<Body>, ) -> impl Future<Output = bool> + Send

Whether a CONNECT request should be intercepted. Defaults to true for all requests.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§