From 79b63d2d73cd05122e948ee99f2fb6e22ed25acb Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 29 Aug 2025 12:10:18 -0300 Subject: [PATCH] feat: add content-length header to responses Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/modes/server/pages.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modes/server/pages.rs b/src/modes/server/pages.rs index 8f3e27a..354e3d3 100644 --- a/src/modes/server/pages.rs +++ b/src/modes/server/pages.rs @@ -40,14 +40,22 @@ pub fn add_routes(app: axum::Router) -> axum::Router { async fn list_items( State(state): State, Query(params): Query, -) -> Result, Html> { +) -> Result> { let conn = state.db.lock().await; let settings = &state.settings; let result = build_item_list(&conn, ¶ms, &settings.list_format); match result { - Ok(html) => Ok(Html(html)), + Ok(html) => { + // Build response with explicit Content-Length + let response = Response::builder() + .header("content-type", "text/html") + .header("content-length", html.len().to_string()) + .body(axum::body::Body::from(html)) + .map_err(|_| Html("Internal Server Error".to_string()))?; + Ok(response) + }, Err(e) => Err(Html(format!("Error: {}", e))), } } @@ -239,13 +247,21 @@ async fn style_css() -> &'static str { async fn show_item( State(state): State, Path(id): Path, -) -> Result, Html> { +) -> Result> { let conn = state.db.lock().await; let result = build_item_details(&conn, id); match result { - Ok(html) => Ok(Html(html)), + Ok(html) => { + // Build response with explicit Content-Length + let response = Response::builder() + .header("content-type", "text/html") + .header("content-length", html.len().to_string()) + .body(axum::body::Body::from(html)) + .map_err(|_| Html("Internal Server Error".to_string()))?; + Ok(response) + }, Err(e) => Err(Html(format!("Error: {}", e))), } }