1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-25 07:18:35 -06:00

chg: Make the Cache-Control header configurable

This commit is contained in:
Sayantan Santra 2024-05-31 01:41:55 -05:00
parent eab1c9bc73
commit 8ff4c3f24f
Signed by: SinTan1729
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)