pub struct ConnectionShutdown { /* private fields */ }Expand description
A handle to the connection that dispatched the current request.
axum-server adds this to the extensions of every request, so a handler can close the connection it is running on:
use axum::{extract::Extension, routing::get, Router};
use axum_server::ConnectionShutdown;
async fn handle(Extension(shutdown): Extension<ConnectionShutdown>) -> &'static str {
shutdown.graceful_shutdown();
"goodbye"
}
let app: Router = Router::new().route("/", get(handle));The handle can be moved into another task to close the connection later, for example to enforce a deadline on a slow client.
An HTTP/2 connection carries many streams, so closing it closes all of them.
Implementations§
Source§impl ConnectionShutdown
impl ConnectionShutdown
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Close the connection immediately.
The in-flight request is cancelled, so its response may not be sent.
Use graceful_shutdown to let the response
finish.
Sourcepub fn graceful_shutdown(&self)
pub fn graceful_shutdown(&self)
Close the connection after the in-flight response is sent.
The current response is still delivered and no further requests are accepted on the connection.
Trait Implementations§
Source§impl Clone for ConnectionShutdown
impl Clone for ConnectionShutdown
Auto Trait Implementations§
impl !RefUnwindSafe for ConnectionShutdown
impl !UnwindSafe for ConnectionShutdown
impl Forget for ConnectionShutdown
impl Freeze for ConnectionShutdown
impl Send for ConnectionShutdown
impl Sync for ConnectionShutdown
impl Unpin for ConnectionShutdown
impl UnsafeUnpin for ConnectionShutdown
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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