pub struct ServerBuilder<M: Metadata = (), S: Middleware<M> = Noop> { /* private fields */ }
Expand description
Convenient JSON-RPC HTTP Server builder.
Implementations§
Source§impl<M, S: Middleware<M>> ServerBuilder<M, S>
impl<M, 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
.
By default:
- Server is not sending any CORS headers.
- Server is validating
Host
header.
Source§impl<M, S: Middleware<M>> ServerBuilder<M, S>
impl<M, S: Middleware<M>> ServerBuilder<M, S>
Sourcepub fn with_meta_extractor<T, E>(handler: T, extractor: E) -> Self
pub fn with_meta_extractor<T, E>(handler: T, extractor: E) -> Self
Creates new ServerBuilder
for given IoHandler
.
By default:
- Server is not sending any CORS headers.
- Server is validating
Host
header.
Sourcepub fn event_loop_executor(self, executor: TaskExecutor) -> Self
pub fn event_loop_executor(self, executor: TaskExecutor) -> Self
Utilize existing event loop executor to poll RPC results.
Applies only to 1 of the threads. Other threads will spawn their own Event Loops.
Sourcepub fn rest_api(self, rest_api: RestApi) -> Self
pub fn rest_api(self, rest_api: RestApi) -> Self
Enable the REST -> RPC converter.
Allows you to invoke RPCs by sending POST /<method>/<param1>/<param2>
requests
(with no body). Disabled by default.
Sourcepub fn health_api<A, B, T>(self, health_api: T) -> Self
pub fn health_api<A, B, T>(self, health_api: T) -> Self
Enable health endpoint.
Allows you to expose one of the methods under GET /<path>
The method will be invoked with no parameters.
Error returned from the method will be converted to status 500
response.
Expects a tuple with (<path>, <rpc-method-name>)
.
Sourcepub fn keep_alive(self, val: bool) -> Self
pub fn keep_alive(self, val: bool) -> Self
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 cors_max_age<T: Into<Option<u32>>>(self, cors_max_age: T) -> Self
pub fn cors_max_age<T: Into<Option<u32>>>(self, cors_max_age: T) -> Self
Configure CORS AccessControlMaxAge
header returned.
Informs the client that the CORS preflight request is not necessary for cors_max_age
seconds.
Disabled by default.
Sourcepub fn cors_allow_headers(
self,
allowed_headers: AccessControlAllowHeaders,
) -> Self
pub fn cors_allow_headers( self, allowed_headers: AccessControlAllowHeaders, ) -> Self
Configure the CORS AccessControlAllowHeaders
header which are allowed.
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 max_request_body_size(self, val: usize) -> Self
pub fn max_request_body_size(self, val: usize) -> Self
Sets the maximum size of a request body in bytes (default is 5 MiB).
Sourcepub fn start_http(self, addr: &SocketAddr) -> Result<Server>
pub fn start_http(self, addr: &SocketAddr) -> Result<Server>
Start this JSON-RPC HTTP server trying to bind to specified SocketAddr
.