global: snapshot

This commit is contained in:
k
2024-09-16 13:17:18 +02:00
parent f95eb0f1c9
commit 9dbffb0c93
83 changed files with 1812 additions and 1134 deletions

View File

@@ -88,7 +88,7 @@ where
headers.insert_cors();
headers.insert_content_type_application_json();
headers.insert_cache_control(max_age, stale_while_revalidate);
headers.insert_cache_control_revalidate(max_age, stale_while_revalidate);
response
}

View File

@@ -16,7 +16,8 @@ pub trait HeaderMapUtils {
fn insert_cors(&mut self);
fn insert_cache_control(&mut self, max_age: u64, stale_while_revalidate: u64);
fn insert_cache_control_immutable(&mut self);
fn insert_cache_control_revalidate(&mut self, max_age: u64, stale_while_revalidate: u64);
fn insert_last_modified(&mut self, date: DateTime<Utc>);
fn insert_content_type(&mut self, path: &Path);
@@ -62,7 +63,16 @@ impl HeaderMapUtils for HeaderMap {
self.insert(header::ACCESS_CONTROL_ALLOW_HEADERS, "*".parse().unwrap());
}
fn insert_cache_control(&mut self, max_age: u64, stale_while_revalidate: u64) {
fn insert_cache_control_immutable(&mut self) {
self.insert(
header::CACHE_CONTROL,
format!("public, max-age=604800, immutable, stale-if-error={STALE_IF_ERROR}")
.parse()
.unwrap(),
);
}
fn insert_cache_control_revalidate(&mut self, max_age: u64, stale_while_revalidate: u64) {
self.insert(
header::CACHE_CONTROL,
format!(

View File

@@ -74,7 +74,13 @@ fn path_to_response(headers: HeaderMap, path: &Path) -> Response {
headers.insert_content_type(path);
if !is_localhost {
headers.insert_cache_control(10, 50);
let serialized_path = path.to_str().unwrap();
if serialized_path.contains("fonts/") || serialized_path.contains("assets/pwa/") || serialized_path.contains("packages/") {
headers.insert_cache_control_immutable();
} else {
headers.insert_cache_control_revalidate(10, 50);
}
}
headers.insert_last_modified(date);

View File

@@ -1,3 +0,0 @@
mod js;
pub use js::*;