httpd: Only return cache header on success

This commit is contained in:
Sebastian Martinez 2024-03-20 11:53:52 +01:00 committed by cloudhead
parent 04a4aa06c9
commit 3aca2a11b0
No known key found for this signature in database
1 changed files with 7 additions and 2 deletions

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))
},
)),
),
)