pub struct ServerConfig { /* private fields */ }std only.Expand description
Settings for Server.
| Setting | Default |
|---|---|
| limits | Limits::new |
| concurrent connections | 64 (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 | 10 s |
§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
impl ServerConfig
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults (see the table on ServerConfig).
§Examples
assert_eq!(http_net::blocking::ServerConfig::new().max_connections(), 64);Sourcepub const fn with_limits(self, limits: Limits) -> Self
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);Sourcepub const fn with_max_connections(self, n: usize) -> Self
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);Sourcepub const fn with_read_timeout(self, timeout: Option<Duration>) -> Self
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);Sourcepub const fn with_request_timeout(self, timeout: Option<Duration>) -> Self
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)));Sourcepub const fn with_write_timeout(self, timeout: Option<Duration>) -> Self
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)));Sourcepub const fn limits(&self) -> Limits
pub const fn limits(&self) -> Limits
The message limits.
§Examples
assert_eq!(http_net::blocking::ServerConfig::new().limits(), http_net::Limits::new());Sourcepub const fn max_connections(&self) -> usize
pub const fn max_connections(&self) -> usize
The concurrent connection cap.
§Examples
assert_eq!(http_net::blocking::ServerConfig::new().max_connections(), 64);Sourcepub const fn read_timeout(&self) -> Option<Duration>
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)));Sourcepub const fn request_timeout(&self) -> Option<Duration>
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)));Sourcepub const fn write_timeout(&self) -> Option<Duration>
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)));