From da3871f39a3a0a7b5b34e2110e41717c33754a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Fri, 17 Mar 2023 22:44:50 +0100 Subject: [PATCH] fix: let requests continue event if client disconnects --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index fe6cfc01..a51416db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,6 +147,7 @@ async fn run_server() -> io::Result<()> { let middlewares = ServiceBuilder::new() .sensitive_headers([header::AUTHORIZATION]) + .layer(axum::middleware::from_fn(spawn_task)) .layer( TraceLayer::new_for_http().make_span_with(|request: &http::Request<_>| { let path = if let Some(path) = request.extensions().get::() { @@ -221,6 +222,15 @@ async fn run_server() -> io::Result<()> { Ok(()) } +async fn spawn_task( + req: axum::http::Request, + next: axum::middleware::Next, +) -> std::result::Result { + tokio::spawn(next.run(req)) + .await + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) +} + async fn unrecognized_method( req: axum::http::Request, next: axum::middleware::Next,