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