mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 00:59:58 -07:00
global: snapshot
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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!(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
mod js;
|
||||
|
||||
pub use js::*;
|
||||
Reference in New Issue
Block a user