Skip to main content

HttpApplication

Struct HttpApplication 

Source
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

Source

pub const fn application(&self) -> &Application

Returns the underlying bootstrapped application.

Source

pub const fn router(&self) -> &Router

Returns the composed Axum router.

Source

pub fn map_router(self, map: impl FnOnce(Router) -> Router) -> Self

Transforms the composed Axum router while preserving the bootstrapped application.

Source

pub fn into_router(self) -> Router

Consumes this HTTP application and returns its composed router.

Source

pub async fn bind<A>(&self, address: A) -> Result<TcpListener>
where A: ToSocketAddrs,

Binds a TCP listener for this application without starting the server.

Source

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).

Source

pub async fn listen_with_graceful_shutdown<A, F>( self, address: A, shutdown: F, ) -> Result<()>
where A: ToSocketAddrs, F: Future<Output = ()> + Send + 'static,

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.

Source

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.

Source

pub async fn serve_with_graceful_shutdown<F>( self, listener: TcpListener, shutdown: F, ) -> Result<()>
where F: Future<Output = ()> + Send + 'static,

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Provider for T
where T: Send + Sync + 'static,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more