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 (each write) | 10 s |
| response deadline (writing one whole response) | 60 s |
| requests per connection | no 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
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: the longest a single read may wait for
bytes (the longest pause within a request), 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 with_response_deadline(self, deadline: Option<Duration>) -> Self
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)));Sourcepub const fn with_max_requests_per_connection(self, max: Option<u64>) -> Self
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));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)));Sourcepub const fn response_deadline(&self) -> Option<Duration>
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)));Sourcepub const fn max_requests_per_connection(&self) -> Option<u64>
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);