pub struct Server { /* private fields */ }Expand description
A native HTTP/1 server whose request execution remains thread-local.
Keeping one compiled app per worker means operation futures, plugin hooks,
and request-scoped dependencies do not need Send or Sync.
Implementations§
Source§impl Server
impl Server
pub fn new(app: ExecutableApp) -> Self
pub fn with_max_body_bytes(self, max_body_bytes: usize) -> Self
Sourcepub fn with_middleware(self, middleware: impl HttpMiddleware + 'static) -> Self
pub fn with_middleware(self, middleware: impl HttpMiddleware + 'static) -> Self
Registers runtime-neutral HTTP middleware in registration order.
Middleware runs for every request this server dispatches, so header policy, compression, rate limiting, and security layers apply on the socket path and not only in the in-memory test client.
Registers middleware whose state is shared with the caller.
Sourcepub const fn with_max_connections(
self,
connections: Option<NonZeroUsize>,
) -> Self
pub const fn with_max_connections( self, connections: Option<NonZeroUsize>, ) -> Self
Bounds concurrently served connections. None accepts without a cap.
A connection accepted while the cap is reached is closed immediately instead of being dispatched.
Sourcepub const fn with_tcp_nodelay(self, nodelay: bool) -> Self
pub const fn with_tcp_nodelay(self, nodelay: bool) -> Self
Enables or disables TCP_NODELAY on accepted sockets. Enabled by
default so a small response is not delayed by Nagle’s algorithm.
pub fn with_limits(self, limits: ServerLimits) -> Self
Sourcepub fn with_openapi(self, config: OpenApiConfig) -> Self
pub fn with_openapi(self, config: OpenApiConfig) -> Self
Mounts precompiled /openapi.json and API reference UI assets.
Sourcepub const fn with_request_timeout(self, timeout: Duration) -> Self
pub const fn with_request_timeout(self, timeout: Duration) -> Self
Sets a wall-clock limit for provider, hook, and handler execution.
Dependency finalizers and response hooks are shielded so cleanup still completes after the timeout fires.
Sourcepub fn serve(self, address: impl ToSocketAddrs) -> Result<()>
pub fn serve(self, address: impl ToSocketAddrs) -> Result<()>
Binds and serves HTTP/1 connections until the process is stopped.
§Errors
Returns a socket error if address resolution, binding, or accepting a connection fails.
Sourcepub fn serve_gracefully(
self,
address: impl ToSocketAddrs,
shutdown: ShutdownSignal,
drain_timeout: Duration,
) -> Result<()>
pub fn serve_gracefully( self, address: impl ToSocketAddrs, shutdown: ShutdownSignal, drain_timeout: Duration, ) -> Result<()>
Stops accepting when shutdown resolves, closes keep-alive
connections after their current response, and drains active work.
§Errors
Returns an I/O error if binding or accepting a connection fails.
Sourcepub async fn serve_io<IO>(&self, io: &mut IO) -> Result<()>
pub async fn serve_io<IO>(&self, io: &mut IO) -> Result<()>
Serves HTTP/1 requests over a borrowed futures-I/O transport.
This is useful for in-memory protocol tests. A borrowed transport cannot
transfer ownership, so protocol upgrades are refused here; owned
transports reach Self::serve and keep the upgrade capability.
§Errors
Returns an I/O error if the transport cannot be read or written.
Sourcepub async fn serve_owned_io<IO>(&self, io: IO) -> Result<()>
pub async fn serve_owned_io<IO>(&self, io: IO) -> Result<()>
Serves HTTP/1 requests over an owned futures-I/O transport.
Ownership stays with the connection loop, so a protocol upgrade moves the transport into its session handler instead of being refused. TLS connections and in-memory compatibility transports take this path.
§Errors
Returns an I/O error if the transport cannot be read or written, or the failure reported by an upgraded protocol session.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Server
impl !Send for Server
impl !Sync for Server
impl !UnwindSafe for Server
impl Freeze for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BackgroundExt for T
impl<T> BackgroundExt for T
fn background(self, task: BackgroundTask) -> Background<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more