From 018b3876b7492d8e9e92110a9c364c65af1cfcf0 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 17 Jun 2026 14:47:22 +0800 Subject: [PATCH] fix: return 404 for bare /uploads path and correct CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ src/main.rs | 13 +++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5347c..956cf0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- 图片响应新增 `Cache-Control` 与 `ETag` 头:原始上传文件使用 `immutable, max-age=31536000`,处理变体使用 `max-age=86400`。 + +### Fixed + +- 修复 `/uploads/{*path}` 路径因缺少 `ConnectInfo` 扩展而返回 HTTP 500 的问题。 + +### Changed + +- 图片解码、缩放、编码逻辑通过 `tokio::task::spawn_blocking` 移至阻塞线程池,避免阻塞异步运行时。 +- 为非图片路由启用 `CompressionLayer` 与 `TimeoutLayer`,`/uploads/*` 图片路由跳过压缩与全局超时。 + ## [0.2.0] - 2026-06-10 ### Added diff --git a/src/main.rs b/src/main.rs index e30875d..b7664f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,10 +110,15 @@ fn main() { )); // 静态资源路由:图片文件服务(不加压缩/超时) - let static_routes = axum::Router::new().route( - "/uploads/{*path}", - axum::routing::get(crate::api::image::serve_image), - ); + let static_routes = axum::Router::new() + .route( + "/uploads/{*path}", + axum::routing::get(crate::api::image::serve_image), + ) + .route( + "/uploads", + axum::routing::get(|| async { StatusCode::NOT_FOUND }), + ); // 合并:upload 路由保持自己独立的 300s 超时;app routes 加压缩/30s;static routes 无任何中间件 let router = upload_route.merge(app_routes).merge(static_routes);