Skip to main content

ServerConfig

Struct ServerConfig 

Source
pub struct ServerConfig { /* private fields */ }

Implementations§

Source§

impl ServerConfig

Source

pub fn create(host: &str, port: u16, setup: FoxtiveSetup) -> ServerConfig

Source

pub fn app(self, app: &str) -> Self

Source

pub fn tracing(self, config: Tracing) -> Self

Source

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

Set number of workers to start.

By default http server uses 2

Source

pub fn backlog(self, backlog: i32) -> Self

Set the maximum number of pending connections.

This refers to the number of clients that can be waiting to be served. Exceeding this number results in the client getting an error when attempting to connect. It should only affect servers under significant load.

Generally set in the 64-2048 range. Default value is 2048.

This method should be called before bind() method call.

Source

pub fn keep_alive(self, keep_alive: Seconds) -> Self

Set server keep-alive setting.

By default keep alive is set to a 5 seconds.

Source

pub fn client_timeout(self, timeout: u16) -> Self

Set request read timeout in seconds.

Defines a timeout for reading client request headers. If a client does not transmit the entire set headers within this time, the request is terminated with the 408 (Request Time-out) error.

To disable timeout set value to 0.

By default client timeout is set to 3 seconds.

Source

pub fn client_disconnect(self, timeout: u16) -> Self

Set server connection disconnect timeout in seconds.

Defines a timeout for shutdown connection. If a shutdown procedure does not complete within this time, the request is dropped.

To disable timeout set value to 0.

By default client timeout is set to 5 seconds.

Source

pub fn max_conn(self, max: usize) -> Self

Sets the maximum per-worker number of concurrent connections.

All socket listeners will stop accepting connections when this limit is reached for each worker.

By default max connections is set to a 25k.

Source

pub fn max_conn_rate(self, max: usize) -> Self

Sets the maximum per-worker concurrent connection establish process.

All listeners will stop accepting connections when this limit is reached. It can be used to limit the global SSL CPU usage.

By default max connections is set to a 256.

Source

pub fn allowed_origins(self, allowed_origins: Vec<String>) -> Self

Source

pub fn allowed_methods(self, allowed_methods: Vec<Method>) -> Self

Source

pub fn boot_thread( self, boot_thread: Arc<dyn Fn() -> Vec<Route> + Send + Sync>, ) -> Self

Source

pub fn has_started_bootstrap(self, has_started_bootstrap: bool) -> Self

Source

pub fn json_config(self, json_config: JsonConfig) -> Self

Source

pub fn on_shutdown<F>(self, func: F) -> Self
where F: Future<Output = ()> + Send + 'static,

Sets a custom shutdown handler to be called when the application is shutting down.

This method allows you to provide a future that will be awaited during shutdown. It is typically used to perform cleanup tasks like closing database connections, flushing logs, or other async teardown operations.

Note: If a custom shutdown_signal is also provided using [shutdown_signal], that will take precedence over this handler, and this on_shutdown handler will not be executed.

Source

pub fn shutdown_signal<F>(self, func: F) -> Self
where F: Future<Output = ()> + Send + 'static,

Sets a custom shutdown signal handler that determines when the application should begin shutting down.

This method allows you to provide a future that, when resolved, triggers the application shutdown. It is typically used to listen for signals like Ctrl+C or system termination requests (SIGTERM).

If this shutdown signal is provided, it will override any handler set using [on_shutdown].

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more