Skip to main content

ServerConfig

Struct ServerConfig 

Source
pub struct ServerConfig { /* private fields */ }
Available on crate feature std only.
Expand description

Settings for Server.

SettingDefault
limitsLimits::new
concurrent connections64 (the 65th is answered 503 and closed)
read timeout (also the idle keep-alive timeout)10 s
request timeout (first byte of a request to the end of its body)30 s
write timeout (each write)10 s
response deadline (writing one whole response)60 s
requests per connectionno cap

§Examples

use std::time::Duration;
use http_net::{blocking::ServerConfig, Limits};

let config = ServerConfig::new()
    .with_limits(Limits::new().with_max_body(16 * 1024))
    .with_max_connections(8)
    .with_read_timeout(Some(Duration::from_secs(5)));
assert_eq!(config.max_connections(), 8);

Implementations§

Source§

impl ServerConfig

Source

pub const fn new() -> Self

The defaults (see the table on ServerConfig).

§Examples
assert_eq!(http_net::blocking::ServerConfig::new().max_connections(), 64);
Source

pub const fn with_limits(self, limits: Limits) -> Self

Sets the message limits for every connection.

§Examples
let c = http_net::blocking::ServerConfig::new()
    .with_limits(http_net::Limits::new().with_max_headers(10));
assert_eq!(c.limits().max_headers(), 10);
Source

pub const fn with_max_connections(self, n: usize) -> Self

Sets how many connections are served at once (at least 1).

§Examples
let c = http_net::blocking::ServerConfig::new().with_max_connections(0);
assert_eq!(c.max_connections(), 1);
Source

pub const fn with_read_timeout(self, timeout: Option<Duration>) -> Self

Sets the socket read timeout: how long a request may take to arrive, and how long an idle keep-alive connection is held. None waits forever.

§Examples
let c = http_net::blocking::ServerConfig::new().with_read_timeout(None);
assert_eq!(c.read_timeout(), None);
Source

pub const fn with_request_timeout(self, timeout: Option<Duration>) -> Self

Sets the request timeout: the most time one request may take to arrive, from its first byte to the end of its body. The read timeout alone cannot stop a client that sends one byte just inside it (“slowloris”); this deadline can. A request still incomplete when it passes is answered 408 Request Timeout and the connection closed. Time spent idle between keep-alive requests does not count (the read timeout governs that). None disables the deadline.

§Examples
use std::time::Duration;
let c = http_net::blocking::ServerConfig::new().with_request_timeout(Some(Duration::from_secs(10)));
assert_eq!(c.request_timeout(), Some(Duration::from_secs(10)));
Source

pub const fn with_write_timeout(self, timeout: Option<Duration>) -> Self

Sets the socket write timeout. None waits forever.

§Examples
use std::time::Duration;
let c = http_net::blocking::ServerConfig::new().with_write_timeout(Some(Duration::from_secs(1)));
assert_eq!(c.write_timeout(), Some(Duration::from_secs(1)));
Source

pub const fn with_response_deadline(self, deadline: Option<Duration>) -> Self

Sets the response deadline: the most time writing one response may take, from its first byte to its last (a streamed body included). The write timeout bounds each write; it cannot stop a client that reads one byte just inside it and so holds a thread for as long as a large response takes. This deadline can: when it passes, the connection is closed. None disables it.

§Examples
use std::time::Duration;
let c = http_net::blocking::ServerConfig::new().with_response_deadline(Some(Duration::from_secs(5)));
assert_eq!(c.response_deadline(), Some(Duration::from_secs(5)));
Source

pub const fn with_max_requests_per_connection(self, max: Option<u64>) -> Self

Sets the most requests served on one connection: the response that reaches the cap carries connection: close and the connection ends after it. Some(0) is raised to 1; None (the default) sets no cap.

§Examples
let c = http_net::blocking::ServerConfig::new().with_max_requests_per_connection(Some(100));
assert_eq!(c.max_requests_per_connection(), Some(100));
Source

pub const fn limits(&self) -> Limits

The message limits.

§Examples
assert_eq!(http_net::blocking::ServerConfig::new().limits(), http_net::Limits::new());
Source

pub const fn max_connections(&self) -> usize

The concurrent connection cap.

§Examples
assert_eq!(http_net::blocking::ServerConfig::new().max_connections(), 64);
Source

pub const fn read_timeout(&self) -> Option<Duration>

The read timeout.

§Examples
use std::time::Duration;
assert_eq!(http_net::blocking::ServerConfig::new().read_timeout(), Some(Duration::from_secs(10)));
Source

pub const fn request_timeout(&self) -> Option<Duration>

The request timeout.

§Examples
use std::time::Duration;
assert_eq!(http_net::blocking::ServerConfig::new().request_timeout(), Some(Duration::from_secs(30)));
Source

pub const fn write_timeout(&self) -> Option<Duration>

The write timeout.

§Examples
use std::time::Duration;
assert_eq!(http_net::blocking::ServerConfig::new().write_timeout(), Some(Duration::from_secs(10)));
Source

pub const fn response_deadline(&self) -> Option<Duration>

The response deadline.

§Examples
use std::time::Duration;
assert_eq!(http_net::blocking::ServerConfig::new().response_deadline(), Some(Duration::from_secs(60)));
Source

pub const fn max_requests_per_connection(&self) -> Option<u64>

The cap on requests per connection.

§Examples
assert_eq!(http_net::blocking::ServerConfig::new().max_requests_per_connection(), None);

Trait Implementations§

Source§

impl Clone for ServerConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ServerConfig

Source§

impl Debug for ServerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ServerConfig

Source§

impl PartialEq for ServerConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ServerConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.