Trait jsonrpsee_core::middleware::WsMiddleware
source · pub trait WsMiddleware: Send + Sync + Clone + 'static {
type Instant: Debug + Send + Sync + Copy;
fn on_connect(&self, remote_addr: SocketAddr, headers: &Headers);
fn on_request(&self) -> 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);
fn on_disconnect(&self, remote_addr: SocketAddr);
}
Expand description
Defines a middleware specifically for WebSocket connections 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 the WsServerBuilder::set_middleware
for examples.
Required Associated Types§
Required Methods§
sourcefn on_connect(&self, remote_addr: SocketAddr, headers: &Headers)
fn on_connect(&self, remote_addr: SocketAddr, headers: &Headers)
Called when a new client connects
sourcefn on_request(&self) -> Self::Instant
fn on_request(&self) -> Self::Instant
Called when a new JSON-RPC request comes to the server.
sourcefn on_call(&self, method_name: &str, params: Params<'_>, kind: MethodKind)
fn on_call(&self, method_name: &str, params: Params<'_>, kind: MethodKind)
Called on each JSON-RPC method call, batch requests will trigger on_call
multiple times.
sourcefn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant)
fn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant)
Called on each JSON-RPC method completion, batch requests will trigger on_result
multiple times.
sourcefn on_response(&self, result: &str, started_at: Self::Instant)
fn on_response(&self, result: &str, started_at: Self::Instant)
Called once the JSON-RPC request is finished and response is sent to the output buffer.
sourcefn on_disconnect(&self, remote_addr: SocketAddr)
fn on_disconnect(&self, remote_addr: SocketAddr)
Called when a client disconnects