feat: add content-length header to responses

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-29 12:10:18 -03:00
parent 47fd796d50
commit 79b63d2d73

View File

@@ -40,14 +40,22 @@ pub fn add_routes(app: axum::Router<AppState>) -> axum::Router<AppState> {
async fn list_items( async fn list_items(
State(state): State<AppState>, State(state): State<AppState>,
Query(params): Query<ListQueryParams>, Query(params): Query<ListQueryParams>,
) -> Result<Html<String>, Html<String>> { ) -> Result<Response, Html<String>> {
let conn = state.db.lock().await; let conn = state.db.lock().await;
let settings = &state.settings; let settings = &state.settings;
let result = build_item_list(&conn, &params, &settings.list_format); let result = build_item_list(&conn, &params, &settings.list_format);
match result { 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("<html><body>Internal Server Error</body></html>".to_string()))?;
Ok(response)
},
Err(e) => Err(Html(format!("<html><body>Error: {}</body></html>", e))), Err(e) => Err(Html(format!("<html><body>Error: {}</body></html>", e))),
} }
} }
@@ -239,13 +247,21 @@ async fn style_css() -> &'static str {
async fn show_item( async fn show_item(
State(state): State<AppState>, State(state): State<AppState>,
Path(id): Path<i64>, Path(id): Path<i64>,
) -> Result<Html<String>, Html<String>> { ) -> Result<Response, Html<String>> {
let conn = state.db.lock().await; let conn = state.db.lock().await;
let result = build_item_details(&conn, id); let result = build_item_details(&conn, id);
match result { 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("<html><body>Internal Server Error</body></html>".to_string()))?;
Ok(response)
},
Err(e) => Err(Html(format!("<html><body>Error: {}</body></html>", e))), Err(e) => Err(Html(format!("<html><body>Error: {}</body></html>", e))),
} }
} }