pub struct ServerBuilder { /* private fields */ }Expand description
Builds a Server with optional policy and timeout configuration.
You use ServerBuilder when you want a fluent, explicit configuration surface for
CORS, custom headers, timeouts, and rate limiting.
§Examples
use http_handle::Server;
let server = Server::builder()
.address("127.0.0.1:8080")
.document_root(".")
.enable_cors()
.build()
.expect("valid builder config");
assert_eq!(server.address(), "127.0.0.1:8080");§Errors
Builder finalization fails when required fields are missing.
§Panics
This type does not panic under normal usage.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn document_root(self, path: &str) -> Self
pub fn document_root(self, path: &str) -> Self
Sets the document root directory used for file resolution.
§Examples
use http_handle::Server;
let server = Server::builder()
.address("127.0.0.1:8080")
.document_root(".")
.build()
.expect("builder should succeed");
assert_eq!(server.document_root().as_path(), std::path::Path::new("."));§Panics
This function does not panic.
Sourcepub fn enable_cors(self) -> Self
pub fn enable_cors(self) -> Self
Enables CORS with default settings
Sourcepub fn disable_cors(self) -> Self
pub fn disable_cors(self) -> Self
Disables CORS
Sourcepub fn cors_origins(self, origins: Vec<String>) -> Self
pub fn cors_origins(self, origins: Vec<String>) -> Self
Sets allowed CORS origins
Sourcepub fn custom_header(self, name: &str, value: &str) -> Self
pub fn custom_header(self, name: &str, value: &str) -> Self
Adds a custom header that will be included in all responses
Sourcepub fn custom_headers(self, headers: HashMap<String, String>) -> Self
pub fn custom_headers(self, headers: HashMap<String, String>) -> Self
Sets multiple custom headers
Sourcepub fn request_timeout(self, timeout: Duration) -> Self
pub fn request_timeout(self, timeout: Duration) -> Self
Sets the request timeout duration
Sourcepub fn connection_timeout(self, timeout: Duration) -> Self
pub fn connection_timeout(self, timeout: Duration) -> Self
Sets the connection timeout duration
Sourcepub fn rate_limit_per_minute(self, requests: usize) -> Self
pub fn rate_limit_per_minute(self, requests: usize) -> Self
Sets a simple per-IP request rate limit per minute.
Sourcepub fn static_cache_ttl_secs(self, ttl: u64) -> Self
pub fn static_cache_ttl_secs(self, ttl: u64) -> Self
Sets a default static cache max-age (in seconds).
Sourcepub fn build(self) -> Result<Server, &'static str>
pub fn build(self) -> Result<Server, &'static str>
Finalizes builder state into a Server.
§Examples
use http_handle::Server;
let ok = Server::builder()
.address("127.0.0.1:8080")
.document_root(".")
.build();
assert!(ok.is_ok());§Errors
Returns Err when:
- the address was not provided.
- the document root was not provided.
§Panics
This function does not panic.
Trait Implementations§
Source§impl Clone for ServerBuilder
impl Clone for ServerBuilder
Source§fn clone(&self) -> ServerBuilder
fn clone(&self) -> ServerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more