Skip to main content

reth_rpc_builder/
middleware.rs

1use jsonrpsee::server::{
2    middleware::rpc::RpcService, HttpRequest, HttpResponse, TowerServiceNoHttp,
3};
4use tower::{
5    layer::util::{Identity, Stack},
6    Layer,
7};
8
9/// A Helper alias trait for the RPC middleware supported by the server.
10pub trait RethRpcMiddleware:
11    Layer<
12        RpcService,
13        Service: jsonrpsee::server::middleware::rpc::RpcServiceT + Send + Sync + Clone + 'static,
14    > + Clone
15    + Send
16    + 'static
17{
18}
19
20impl<T> RethRpcMiddleware for T where
21    T: Layer<
22            RpcService,
23            Service: jsonrpsee::server::middleware::rpc::RpcServiceT
24                         + Send
25                         + Sync
26                         + Clone
27                         + 'static,
28        > + Clone
29        + Send
30        + 'static
31{
32}
33
34/// Inner HTTP transport service type for auth-server middleware.
35pub type AuthHttpService<RM> = TowerServiceNoHttp<Stack<RM, Identity>>;
36
37/// Helper alias trait for auth-server HTTP transport middleware layers.
38pub trait RethAuthHttpMiddleware<RM>:
39    tower::Layer<
40        AuthHttpService<RM>,
41        Service: tower::Service<
42            HttpRequest,
43            Response = HttpResponse,
44            Error = tower::BoxError,
45            Future: Send,
46        > + Send
47                     + Clone,
48    > + Clone
49    + Send
50    + 'static
51{
52}
53
54impl<T, RM> RethAuthHttpMiddleware<RM> for T where
55    T: tower::Layer<
56            AuthHttpService<RM>,
57            Service: tower::Service<
58                HttpRequest,
59                Response = HttpResponse,
60                Error = tower::BoxError,
61                Future: Send,
62            > + Send
63                         + Clone,
64        > + Clone
65        + Send
66        + 'static
67{
68}