pub struct ServerConfigBuilder(/* private fields */);Expand description
The builder to configure and create a JSON-RPC server configuration.
Implementations§
Source§impl ServerConfigBuilder
impl ServerConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ServerConfigBuilder.
Sourcepub fn max_request_body_size(self, size: u32) -> Self
pub fn max_request_body_size(self, size: u32) -> Self
Set the maximum size of a request body in bytes. Default is 10 MiB.
Sourcepub fn max_response_body_size(self, size: u32) -> Self
pub fn max_response_body_size(self, size: u32) -> Self
Set the maximum size of a response body in bytes. Default is 10 MiB.
Sourcepub fn max_connections(self, max: u32) -> Self
pub fn max_connections(self, max: u32) -> Self
Set the maximum number of connections allowed. Default is 100.
Sourcepub fn max_subscriptions_per_connection(self, max: u32) -> Self
pub fn max_subscriptions_per_connection(self, max: u32) -> Self
Set the maximum number of subscriptions per connection. Default is 1024.
Sourcepub fn set_batch_request_config(self, cfg: BatchRequestConfig) -> Self
pub fn set_batch_request_config(self, cfg: BatchRequestConfig) -> Self
Configure how batch requests shall be handled by the server.
Default: batch requests are allowed and can be arbitrary big but the maximum payload size is limited.
Sourcepub fn custom_tokio_runtime(self, rt: Handle) -> Self
pub fn custom_tokio_runtime(self, rt: Handle) -> Self
Configure a custom [tokio::runtime::Handle] to run the server on.
Default: [tokio::spawn]
Sourcepub fn http_only(self) -> Self
pub fn http_only(self) -> Self
Configure the server to only serve JSON-RPC HTTP requests.
Default: both http and ws are enabled.
Sourcepub fn ws_only(self) -> Self
pub fn ws_only(self) -> Self
Configure the server to only serve JSON-RPC WebSocket requests.
That implies that server just denies HTTP requests which isn’t a WebSocket upgrade request
Default: both http and ws are enabled.
Sourcepub fn set_message_buffer_capacity(self, c: u32) -> Self
pub fn set_message_buffer_capacity(self, c: u32) -> Self
The server enforces backpressure which means that
n messages can be buffered and if the client
can’t keep with up the server.
This capacity is applied per connection and
applies globally on the connection which implies
all JSON-RPC messages.
It is the number of messages (responses and subscription notifications) that can wait to be written to the client, and also the most calls a WebSocket connection runs at once.
For example if a subscription produces plenty of new items and the client can’t keep up then no new messages are handled.
If the client can’t keep up then calls wait to queue their response. Once that many calls are running, the server stops reading new messages from the connection until one completes.
§Panics
Panics if the buffer capacity is 0.
Sourcepub fn set_id_provider<I: IdProvider + 'static>(self, id_provider: I) -> Self
pub fn set_id_provider<I: IdProvider + 'static>(self, id_provider: I) -> Self
Configure custom subscription ID provider for the server to use
to when getting new subscription calls.
You may choose static dispatch or dynamic dispatch because
IdProvider is implemented for Box<T>.
Default: RandomIntegerIdProvider.
§Examples
use jsonrpsee_server::{IdProvider, RandomStringIdProvider, ServerConfigBuilder};
// static dispatch
let builder1 = ServerConfigBuilder::default().set_id_provider(RandomStringIdProvider::new(16));
// or dynamic dispatch
let builder2 =
ServerConfigBuilder::default().set_id_provider(Box::new(RandomStringIdProvider::new(16)));Sourcepub fn set_first_request_timeout(
self,
first_request_timeout: Option<Duration>,
) -> Self
pub fn set_first_request_timeout( self, first_request_timeout: Option<Duration>, ) -> Self
Configure how long a connection may take to send its first request, e.g. the WebSocket
upgrade request, before it is closed. None disables the timeout.
Default is 30 seconds.
Sourcepub fn set_write_timeout(self, write_timeout: Duration) -> Self
pub fn set_write_timeout(self, write_timeout: Duration) -> Self
Configure how long writing a single message, ping or close frame to a WebSocket connection may take, and how long an HTTP response write may make no progress, before the connection is closed.
A client that stops reading fills the socket’s send buffer, which blocks the write. When the timeout expires, the connection is dropped together with its queued messages, subscriptions and pending calls, or with its buffered HTTP response.
Default is 10 seconds.
Sourcepub fn build(self) -> ServerConfig
pub fn build(self) -> ServerConfig
Build the ServerConfig.
Trait Implementations§
Source§impl Clone for ServerConfigBuilder
impl Clone for ServerConfigBuilder
Source§impl Debug for ServerConfigBuilder
impl Debug for ServerConfigBuilder
Auto Trait Implementations§
impl !RefUnwindSafe for ServerConfigBuilder
impl !UnwindSafe for ServerConfigBuilder
impl Freeze for ServerConfigBuilder
impl Send for ServerConfigBuilder
impl Sync for ServerConfigBuilder
impl Unpin for ServerConfigBuilder
impl UnsafeUnpin for ServerConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 96 bytes