diff --git a/src/modes/server/common.rs b/src/modes/server/common.rs index 14ba2b3..61d53b4 100644 --- a/src/modes/server/common.rs +++ b/src/modes/server/common.rs @@ -206,7 +206,7 @@ pub async fn logging_middleware( ) -> Response { let method = request.method().clone(); let uri = request.uri().clone(); - let content_length = request.headers() + let request_content_length = request.headers() .get("content-length") .and_then(|v| v.to_str().ok()) .and_then(|s| s.parse::().ok()) @@ -216,7 +216,14 @@ pub async fn logging_middleware( let response = next.run(request).await; let duration = start.elapsed(); - info!("{} {} {} {} {} bytes - {:?}", addr, method, uri, response.status(), content_length, duration); + // Try to get response body size from content-length header, or default to 0 + let response_content_length = response.headers() + .get("content-length") + .and_then(|v| v.to_str().ok()) + .and_then(|s| s.parse::().ok()) + .unwrap_or(0); + + info!("{} {} {} {} {} bytes - {:?}", addr, method, uri, response.status(), response_content_length, duration); response }