httpd: Only return cache header on success

This commit is contained in:
Sebastian Martinez
2024-03-21 12:45:13 +01:00
committed by cloudhead
parent 3fb08329ab
commit 22c83c556f
+7 -2
View File
@@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap};
use axum::extract::{DefaultBodyLimit, State};
use axum::handler::Handler;
use axum::http::{header, HeaderValue};
use axum::response::IntoResponse;
use axum::response::{IntoResponse, Response};
use axum::routing::{get, patch, post};
use axum::{Json, Router};
use axum_auth::AuthBearer;
@@ -43,7 +43,12 @@ pub fn router(ctx: Context) -> Router {
get(
activity_handler.layer(SetResponseHeaderLayer::if_not_present(
header::CACHE_CONTROL,
HeaderValue::from_static(CACHE_1_HOUR),
|response: &Response| {
response
.status()
.is_success()
.then_some(HeaderValue::from_static(CACHE_1_HOUR))
},
)),
),
)