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:
@@ -40,14 +40,22 @@ pub fn add_routes(app: axum::Router<AppState>) -> axum::Router<AppState> {
|
||||
async fn list_items(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<ListQueryParams>,
|
||||
) -> Result<Html<String>, Html<String>> {
|
||||
) -> Result<Response, Html<String>> {
|
||||
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("<html><body>Internal Server Error</body></html>".to_string()))?;
|
||||
Ok(response)
|
||||
},
|
||||
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(
|
||||
State(state): State<AppState>,
|
||||
Path(id): Path<i64>,
|
||||
) -> Result<Html<String>, Html<String>> {
|
||||
) -> Result<Response, Html<String>> {
|
||||
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("<html><body>Internal Server Error</body></html>".to_string()))?;
|
||||
Ok(response)
|
||||
},
|
||||
Err(e) => Err(Html(format!("<html><body>Error: {}</body></html>", e))),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user