pub struct HttpApplication { /* private fields */ }Expand description
A bootstrapped Nidus application with an Axum router ready to serve.
All serving methods (Self::listen, Self::serve, and their
*_with_graceful_shutdown variants) wrap the router with Axum’s
into_make_service_with_connect_info::<SocketAddr>(). This populates the
axum::extract::ConnectInfo<SocketAddr> extension for every connection, so
handlers and identity extractors such as
crate::context::client_ip_identity classify clients by their real peer
address instead of falling through to the spoofable X-Forwarded-For header
or a shared "anonymous" bucket.
Implementations§
Source§impl HttpApplication
impl HttpApplication
Sourcepub const fn application(&self) -> &Application
pub const fn application(&self) -> &Application
Returns the underlying bootstrapped application.
Sourcepub fn map_router(self, map: impl FnOnce(Router) -> Router) -> Self
pub fn map_router(self, map: impl FnOnce(Router) -> Router) -> Self
Transforms the composed Axum router while preserving the bootstrapped application.
Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
Consumes this HTTP application and returns its composed router.
Sourcepub async fn bind<A>(&self, address: A) -> Result<TcpListener>where
A: ToSocketAddrs,
pub async fn bind<A>(&self, address: A) -> Result<TcpListener>where
A: ToSocketAddrs,
Binds a TCP listener for this application without starting the server.
Sourcepub async fn listen<A>(self, address: A) -> Result<()>where
A: ToSocketAddrs,
pub async fn listen<A>(self, address: A) -> Result<()>where
A: ToSocketAddrs,
Binds address and serves until the server exits.
The router is served with axum::extract::ConnectInfo<SocketAddr>
populated for every connection. This method does not install a
graceful-shutdown signal: the server runs until the process is killed.
For in-flight request draining on a shutdown signal, use
Self::listen_with_graceful_shutdown (or Self::serve /
Self::serve_with_graceful_shutdown with a pre-bound listener).
Sourcepub async fn listen_with_graceful_shutdown<A, F>(
self,
address: A,
shutdown: F,
) -> Result<()>
pub async fn listen_with_graceful_shutdown<A, F>( self, address: A, shutdown: F, ) -> Result<()>
Binds address and serves until shutdown completes, draining in-flight
requests before returning.
shutdown is any future that signals termination (for example a
SIGTERM/Ctrl+C handler in production). While it is pending the server
keeps accepting requests; once it resolves Axum stops accepting and waits
for active connections to finish. axum::extract::ConnectInfo is
populated for every connection.
Sourcepub async fn serve(self, listener: TcpListener) -> Result<()>
pub async fn serve(self, listener: TcpListener) -> Result<()>
Serves the application on a previously bound listener.
Prefer this over Self::listen when you need to control the bind
yourself (for example to read the assigned port, set SO_REUSEPORT, or
share a listener). axum::extract::ConnectInfo<SocketAddr> is
populated for every connection. Like Self::listen, no shutdown signal
is installed.
Sourcepub async fn serve_with_graceful_shutdown<F>(
self,
listener: TcpListener,
shutdown: F,
) -> Result<()>
pub async fn serve_with_graceful_shutdown<F>( self, listener: TcpListener, shutdown: F, ) -> Result<()>
Serves on a previously bound listener until shutdown completes, draining
in-flight requests before returning.
See Self::listen_with_graceful_shutdown for the shutdown semantics;
see Self::serve for why a pre-bound listener is useful.
axum::extract::ConnectInfo<SocketAddr> is populated for every
connection.