fix: let requests continue event if client disconnects
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -147,6 +147,7 @@ async fn run_server() -> io::Result<()> {
|
|||||||
|
|
||||||
let middlewares = ServiceBuilder::new()
|
let middlewares = ServiceBuilder::new()
|
||||||
.sensitive_headers([header::AUTHORIZATION])
|
.sensitive_headers([header::AUTHORIZATION])
|
||||||
|
.layer(axum::middleware::from_fn(spawn_task))
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http().make_span_with(|request: &http::Request<_>| {
|
TraceLayer::new_for_http().make_span_with(|request: &http::Request<_>| {
|
||||||
let path = if let Some(path) = request.extensions().get::<MatchedPath>() {
|
let path = if let Some(path) = request.extensions().get::<MatchedPath>() {
|
||||||
@@ -221,6 +222,15 @@ async fn run_server() -> io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn spawn_task<B: Send + 'static>(
|
||||||
|
req: axum::http::Request<B>,
|
||||||
|
next: axum::middleware::Next<B>,
|
||||||
|
) -> std::result::Result<axum::response::Response, StatusCode> {
|
||||||
|
tokio::spawn(next.run(req))
|
||||||
|
.await
|
||||||
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
}
|
||||||
|
|
||||||
async fn unrecognized_method<B>(
|
async fn unrecognized_method<B>(
|
||||||
req: axum::http::Request<B>,
|
req: axum::http::Request<B>,
|
||||||
next: axum::middleware::Next<B>,
|
next: axum::middleware::Next<B>,
|
||||||
|
|||||||
Reference in New Issue
Block a user