Struct jsonrpsee_http_server::HttpServerBuilder [−][src]
pub struct HttpServerBuilder<M = ()> { /* fields omitted */ }
Expand description
Builder to create JSON-RPC HTTP server.
Implementations
Add a middleware to the builder Middleware
.
use std::time::Instant;
use jsonrpsee_core::middleware::Middleware;
use jsonrpsee_http_server::HttpServerBuilder;
#[derive(Clone)]
struct MyMiddleware;
impl Middleware for MyMiddleware {
type Instant = Instant;
fn on_request(&self) -> Instant {
Instant::now()
}
fn on_result(&self, name: &str, success: bool, started_at: Instant) {
println!("Call to '{}' took {:?}", name, started_at.elapsed());
}
}
let builder = HttpServerBuilder::new().set_middleware(MyMiddleware);
Sets the maximum size of a request body in bytes (default is 10 MiB).
Sets access control settings.
Enables or disables HTTP keep-alive.
Default is true.
Register a new resource kind. Errors if label
is already registered, or if the number of
registered resources on this server instance would exceed 8.
See the module documentation for resurce_limiting
for details.
Configure a custom tokio::runtime::Handle
to run the server on.
Default: tokio::spawn
Finalizes the configuration of the server.
#[tokio::main]
async fn main() {
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let occupied_addr = listener.local_addr().unwrap();
let addrs: &[std::net::SocketAddr] = &[
occupied_addr,
"127.0.0.1:0".parse().unwrap(),
];
assert!(jsonrpsee_http_server::HttpServerBuilder::default().build(occupied_addr).is_err());
assert!(jsonrpsee_http_server::HttpServerBuilder::default().build(addrs).is_ok());
}
Trait Implementations
Auto Trait Implementations
impl<M = ()> !RefUnwindSafe for Builder<M>
impl<M = ()> !UnwindSafe for Builder<M>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more