From 3aca2a11b0178854fe8788eb42b4c2265a0423a1 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 20 Mar 2024 11:53:52 +0100 Subject: [PATCH] httpd: Only return cache header on success --- radicle-httpd/src/api/v1/projects.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 177d5782..7e410a0b 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -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)) + }, )), ), )