chg: Make the Cache-Control header configurable

This commit is contained in:
SinTan1729 2024-05-31 01:41:55 -05:00
parent eab1c9bc73
commit 8ff4c3f24f
No known key found for this signature in database
GPG Key ID: EB3E68BFBA25C85F

View File

@ -34,6 +34,11 @@ async fn main() -> Result<()> {
.parse::<u16>()
.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)