feat: add explicit content-length header to non-streamed item list response
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -35,7 +35,7 @@ use crate::modes::server::common::{AppState, ApiResponse, ItemInfo, TagsQuery, L
|
|||||||
pub async fn handle_list_items(
|
pub async fn handle_list_items(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Query(params): Query<ListItemsQuery>,
|
Query(params): Query<ListItemsQuery>,
|
||||||
) -> Result<Json<ApiResponse<Vec<ItemInfo>>>, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
let tags: Vec<String> = params
|
let tags: Vec<String> = params
|
||||||
.tags
|
.tags
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -93,7 +93,23 @@ pub async fn handle_list_items(
|
|||||||
error: None,
|
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
|
/// Handle as_meta=true response by returning JSON with metadata and content
|
||||||
|
|||||||
Reference in New Issue
Block a user