pub trait HttpMiddleware: Send + Sync + Clone + 'static {
    type Instant: Debug + Send + Sync + Copy;

    fn on_request(
        &self,
        remote_addr: SocketAddr,
        headers: &Headers
    ) -> Self::Instant; fn on_call(&self, method_name: &str, params: Params<'_>, kind: MethodKind); fn on_result(
        &self,
        method_name: &str,
        success: bool,
        started_at: Self::Instant
    ); fn on_response(&self, result: &str, _started_at: Self::Instant); }
Expand description

Defines a middleware specifically for HTTP requests with callbacks during the RPC request life-cycle. The primary use case for this is to collect timings for a larger metrics collection solution.

See HttpServerBuilder::set_middleware method for examples.

Required Associated Types§

Intended to carry timestamp of a request, for example std::time::Instant. How the middleware measures time, if at all, is entirely up to the implementation.

Required Methods§

Called when a new JSON-RPC request comes to the server.

Called on each JSON-RPC method call, batch requests will trigger on_call multiple times.

Called on each JSON-RPC method completion, batch requests will trigger on_result multiple times.

Called once the JSON-RPC request is finished and response is sent to the output buffer.

Implementations on Foreign Types§

Implementors§