build: add route version response header

This commit is contained in:
2026-04-21 01:32:23 +08:00
parent 40d5e4948e
commit c5db90f37a
3 changed files with 12 additions and 3 deletions

View File

@@ -106,7 +106,8 @@
交付物:[../server-rs/apps/api-server/src/response_headers.rs](../server-rs/apps/api-server/src/response_headers.rs)、[../server-rs/apps/api-server/src/app.rs](../server-rs/apps/api-server/src/app.rs)
- [x] 接入 `x-api-version`
交付物:[../server-rs/apps/api-server/src/response_headers.rs](../server-rs/apps/api-server/src/response_headers.rs)
- [ ] 接入 `x-route-version`
- [x] 接入 `x-route-version`
交付物:[../server-rs/apps/api-server/src/response_headers.rs](../server-rs/apps/api-server/src/response_headers.rs)
- [ ] 接入 `x-response-time-ms`
- [ ] 实现 `/healthz`

View File

@@ -61,7 +61,8 @@
1. 所有响应都会回写 `x-request-id`
2. 所有响应都会回写固定的 `x-api-version`,当前值与 body `meta.apiVersion` 保持一致。
3. `x-route-version``x-response-time-ms` 仍留在后续独立任务中补齐
3. 所有响应都会回写 `x-route-version`,当前阶段默认与 `x-api-version` 保持一致,后续再按路由粒度细分
4. `x-response-time-ms` 仍留在后续独立任务中补齐。
## 3. 边界约束

View File

@@ -11,6 +11,7 @@ use crate::{
};
pub const API_VERSION_HEADER: &str = "x-api-version";
pub const ROUTE_VERSION_HEADER: &str = "x-route-version";
pub async fn propagate_request_id_header(request: Request, next: Next) -> Response {
let request_id = resolve_request_id(&request);
@@ -27,7 +28,13 @@ pub async fn propagate_request_id_header(request: Request, next: Next) -> Respon
if let Ok(header_value) = HeaderValue::from_str(API_VERSION) {
response
.headers_mut()
.insert(HeaderName::from_static(API_VERSION_HEADER), header_value);
.insert(
HeaderName::from_static(API_VERSION_HEADER),
header_value.clone(),
);
response
.headers_mut()
.insert(HeaderName::from_static(ROUTE_VERSION_HEADER), header_value);
}
response