Struct ServerBuilder

Source
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>

Source

pub fn new<T>(handler: T) -> Self
where 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:

  1. Server is not sending any CORS headers.
  2. Server is validating Host header.
Source

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.

Source

pub fn keep_alive(self, val: bool) -> Self

Sets Enables or disables HTTP keep-alive. Default is true.

Source

pub fn threads(self, threads: usize) -> Self

Sets number of threads of the server to run. Panics when set to 0.

Source

pub fn cors( self, cors_domains: DomainsValidation<AccessControlAllowOrigin>, ) -> Self

Configures a list of allowed CORS origins.

Source

pub fn request_middleware<T: RequestMiddleware>(self, middleware: T) -> Self

Configures request middleware

Source

pub fn meta_extractor<T: MetaExtractor<M>>(self, extractor: T) -> Self

Configures metadata extractor

Source

pub fn allow_only_bind_host(self) -> Self

Allow connections only with Host header set to binding address.

Source

pub fn allowed_hosts(self, allowed_hosts: DomainsValidation<Host>) -> Self

Specify a list of valid Host headers. Binding address is allowed automatically.

Source

pub fn start_http(self, addr: &SocketAddr) -> ServerResult

Start this JSON-RPC HTTP server trying to bind to specified SocketAddr.

Auto Trait Implementations§

§

impl<M, S> Freeze for ServerBuilder<M, S>

§

impl<M = (), S = Noop> !RefUnwindSafe for ServerBuilder<M, S>

§

impl<M, S> Send for ServerBuilder<M, S>

§

impl<M, S> Sync for ServerBuilder<M, S>

§

impl<M, S> Unpin for ServerBuilder<M, S>

§

impl<M = (), S = Noop> !UnwindSafe for ServerBuilder<M, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.