pub struct ServerBuilder { /* private fields */ }Expand description
Builder for configuring and starting an HTTP server.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn with_cors(self, config: CorsConfig) -> ServerBuilder
pub fn with_cors(self, config: CorsConfig) -> ServerBuilder
Add CORS middleware with the given configuration.
Sourcepub fn with_body_limit(self, max_bytes: u64) -> ServerBuilder
pub fn with_body_limit(self, max_bytes: u64) -> ServerBuilder
Add a request body size limit (in bytes).
Sourcepub fn with_rate_limiter(self, limiter: RateLimiter) -> ServerBuilder
pub fn with_rate_limiter(self, limiter: RateLimiter) -> ServerBuilder
Add rate limiting middleware.
Sourcepub fn with_timeout(self, duration: Duration) -> ServerBuilder
pub fn with_timeout(self, duration: Duration) -> ServerBuilder
Add a request processing timeout.
Sourcepub fn with_max_connections(self, n: usize) -> ServerBuilder
pub fn with_max_connections(self, n: usize) -> ServerBuilder
Set a maximum number of concurrent connections.
Sourcepub fn with_tcp_nodelay(self, nodelay: bool) -> ServerBuilder
pub fn with_tcp_nodelay(self, nodelay: bool) -> ServerBuilder
Enable or disable TCP_NODELAY on accepted connections.
Sourcepub fn with_tcp_keepalive(self, duration: Duration) -> ServerBuilder
pub fn with_tcp_keepalive(self, duration: Duration) -> ServerBuilder
Set the TCP keepalive idle time for accepted connections.
Sourcepub fn with_http2_settings(self, settings: ServerHttp2Settings) -> ServerBuilder
pub fn with_http2_settings(self, settings: ServerHttp2Settings) -> ServerBuilder
Set HTTP/2 server-side connection tuning parameters.
Sourcepub fn with_graceful_shutdown<F>(self, signal: F) -> ServerBuilder
pub fn with_graceful_shutdown<F>(self, signal: F) -> ServerBuilder
Set a graceful shutdown signal.
Sourcepub fn shutdown_on_ctrl_c(self) -> ServerBuilder
pub fn shutdown_on_ctrl_c(self) -> ServerBuilder
Convenience: shut down on Ctrl+C.
Sourcepub async fn serve(self, router: Router) -> Result<(), OxiHttpError>
pub async fn serve(self, router: Router) -> Result<(), OxiHttpError>
Start the server with the given router.
This function runs until the graceful shutdown signal fires or the server encounters a fatal error.
Sourcepub async fn serve_with_addr(
self,
router: Router,
) -> Result<(SocketAddr, JoinHandle<Result<(), OxiHttpError>>), OxiHttpError>
pub async fn serve_with_addr( self, router: Router, ) -> Result<(SocketAddr, JoinHandle<Result<(), OxiHttpError>>), OxiHttpError>
Start the server and return the bound SocketAddr plus a future that
runs the server. Useful for tests where you need the address before
the server starts accepting.
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub async fn listen(self) -> Result<BoundServer, OxiHttpError>
pub async fn listen(self) -> Result<BoundServer, OxiHttpError>
Bind the TCP port eagerly and return a BoundServer handle.
Useful when you need the actual bound address (e.g. when binding port 0) before the server starts accepting connections.
let bound = Server::bind("127.0.0.1:0").listen().await?;
let port = bound.local_addr().port();
println!("Listening on port {port}");
bound.serve(Router::new()).await?;