From 809a1e6e2ca5c8d48ad3eb4c6dbf78a7c2425748 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 29 Aug 2025 11:57:22 -0300 Subject: [PATCH] feat: add explicit content-length header to non-streamed item list response Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/modes/server/api/item.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modes/server/api/item.rs b/src/modes/server/api/item.rs index a8749d3..5831579 100644 --- a/src/modes/server/api/item.rs +++ b/src/modes/server/api/item.rs @@ -35,7 +35,7 @@ use crate::modes::server::common::{AppState, ApiResponse, ItemInfo, TagsQuery, L pub async fn handle_list_items( State(state): State, Query(params): Query, -) -> Result>>, StatusCode> { +) -> Result { let tags: Vec = params .tags .as_ref() @@ -93,7 +93,23 @@ pub async fn handle_list_items( error: None, }; - Ok(Json(response)) + // Serialize to JSON to get the exact length + let json_response = match serde_json::to_vec(&response) { + Ok(data) => data, + Err(e) => { + warn!("Failed to serialize response: {}", e); + return Err(StatusCode::INTERNAL_SERVER_ERROR); + } + }; + + // Build response with explicit Content-Length + let response = Response::builder() + .header(header::CONTENT_TYPE, "application/json") + .header(header::CONTENT_LENGTH, json_response.len().to_string()) + .body(axum::body::Body::from(json_response)) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + + Ok(response) } /// Handle as_meta=true response by returning JSON with metadata and content