pub struct ServerBuilder<M: Metadata = (), S: Middleware<M> = NoopMiddleware> { /* private fields */ }
Expand description
Convenient JSON-RPC HTTP Server builder.
Implementations§
Source§impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S>
impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S>
Sourcepub fn new<T>(handler: T) -> Selfwhere
T: Into<MetaIoHandler<M, S>>,
pub fn new<T>(handler: T) -> Selfwhere
T: Into<MetaIoHandler<M, S>>,
Creates new ServerBuilder
for given IoHandler
.
If you want to re-use the same handler in couple places
see with_remote
function.
By default:
- Server is not sending any CORS headers.
- Server is validating
Host
header.
Sourcepub fn event_loop_remote(self, remote: Remote) -> Self
pub fn event_loop_remote(self, remote: Remote) -> Self
Utilize existing event loop remote to poll RPC results. Applies only to 1 of the threads. Other threads will spawn their own Event Loops.
Sourcepub fn keep_alive(self, val: bool) -> Self
pub fn keep_alive(self, val: bool) -> Self
Sets Enables or disables HTTP keep-alive. Default is true.
Sourcepub fn threads(self, threads: usize) -> Self
pub fn threads(self, threads: usize) -> Self
Sets number of threads of the server to run.
Panics when set to 0
.
Sourcepub fn cors(
self,
cors_domains: DomainsValidation<AccessControlAllowOrigin>,
) -> Self
pub fn cors( self, cors_domains: DomainsValidation<AccessControlAllowOrigin>, ) -> Self
Configures a list of allowed CORS origins.
Sourcepub fn request_middleware<T: RequestMiddleware>(self, middleware: T) -> Self
pub fn request_middleware<T: RequestMiddleware>(self, middleware: T) -> Self
Configures request middleware
Sourcepub fn meta_extractor<T: MetaExtractor<M>>(self, extractor: T) -> Self
pub fn meta_extractor<T: MetaExtractor<M>>(self, extractor: T) -> Self
Configures metadata extractor
Sourcepub fn allow_only_bind_host(self) -> Self
pub fn allow_only_bind_host(self) -> Self
Allow connections only with Host
header set to binding address.
Sourcepub fn allowed_hosts(self, allowed_hosts: DomainsValidation<Host>) -> Self
pub fn allowed_hosts(self, allowed_hosts: DomainsValidation<Host>) -> Self
Specify a list of valid Host
headers. Binding address is allowed automatically.
Sourcepub fn start_http(self, addr: &SocketAddr) -> ServerResult
pub fn start_http(self, addr: &SocketAddr) -> ServerResult
Start this JSON-RPC HTTP server trying to bind to specified SocketAddr
.