fix: log correct response body size in logging middleware
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -206,7 +206,7 @@ pub async fn logging_middleware(
|
|||||||
) -> Response {
|
) -> Response {
|
||||||
let method = request.method().clone();
|
let method = request.method().clone();
|
||||||
let uri = request.uri().clone();
|
let uri = request.uri().clone();
|
||||||
let content_length = request.headers()
|
let request_content_length = request.headers()
|
||||||
.get("content-length")
|
.get("content-length")
|
||||||
.and_then(|v| v.to_str().ok())
|
.and_then(|v| v.to_str().ok())
|
||||||
.and_then(|s| s.parse::<u64>().ok())
|
.and_then(|s| s.parse::<u64>().ok())
|
||||||
@@ -216,7 +216,14 @@ pub async fn logging_middleware(
|
|||||||
let response = next.run(request).await;
|
let response = next.run(request).await;
|
||||||
let duration = start.elapsed();
|
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::<u64>().ok())
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
info!("{} {} {} {} {} bytes - {:?}", addr, method, uri, response.status(), response_content_length, duration);
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user