feat: enhance HTTP logging and API responses with content metadata

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-13 13:20:57 -03:00
parent 8bd918129c
commit b07c9df812
4 changed files with 173 additions and 72 deletions

View File

@@ -58,6 +58,14 @@ pub struct ItemInfo {
pub metadata: HashMap<String, String>,
}
#[derive(Serialize, Deserialize, ToSchema)]
pub struct ItemContentInfo {
#[serde(flatten)]
pub metadata: HashMap<String, String>,
pub content: Option<String>,
pub binary: bool,
}
#[derive(Debug, Deserialize)]
pub struct TagsQuery {
pub tags: Option<String>,
@@ -111,12 +119,17 @@ pub async fn logging_middleware(
) -> Response {
let method = request.method().clone();
let uri = request.uri().clone();
let content_length = request.headers()
.get("content-length")
.and_then(|v| v.to_str().ok())
.and_then(|s| s.parse::<u64>().ok())
.unwrap_or(0);
let start = Instant::now();
let response = next.run(request).await;
let duration = start.elapsed();
info!("{} {} {} {} - {:?}", addr, method, uri, response.status(), duration);
info!("{} {} {} {} {} bytes - {:?}", addr, method, uri, response.status(), content_length, duration);
response
}