From 8ff4c3f24f6c07b561de932fec623f5247a28381 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 31 May 2024 01:41:55 -0500 Subject: [PATCH] chg: Make the Cache-Control header configurable --- actix/src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index f6413c2..09a08b9 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -34,6 +34,11 @@ async fn main() -> Result<()> { .parse::() .expect("Supplied port is not an integer"); + let cache_control_header = env::var("cache_control_header") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or(String::from("Enable")); + // Actually start the server HttpServer::new(move || { App::new() @@ -49,7 +54,11 @@ async fn main() -> Result<()> { .app_data(web::Data::new(AppState { db: database::open_db(db_location.clone()), })) - .wrap(middleware::DefaultHeaders::new().add(("Cache-Control", "no-cache, private"))) + .wrap(if cache_control_header == "Disable" { + middleware::DefaultHeaders::new() + } else { + middleware::DefaultHeaders::new().add(("Cache-Control", "no-cache, private")) + }) .service(services::link_handler) .service(services::getall) .service(services::siteurl)