feat: todo's, add image cache control
This commit is contained in:
39
src/utils.rs
Normal file
39
src/utils.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
pub mod web {
|
||||
/// Macro shenanigans to format a str at compile time
|
||||
pub macro make_static_cache_header($max_age:expr, $stale_revalidate:expr) {{
|
||||
// type guards lmfao
|
||||
const _: ::std::time::Duration = $max_age;
|
||||
const _: ::std::time::Duration = $stale_revalidate;
|
||||
|
||||
// hopefully ident encapsulation will save my ass here
|
||||
const MAX_AGE: u64 = $max_age.as_secs();
|
||||
const STALE_REVALIDATE: u64 = $stale_revalidate.as_secs();
|
||||
|
||||
const_str::format!(
|
||||
"public, max-age={}, stale-while-revalidate={}",
|
||||
MAX_AGE,
|
||||
STALE_REVALIDATE
|
||||
)
|
||||
}}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn const_concat_worked() {
|
||||
const MA: Duration = Duration::from_mins(15);
|
||||
const SR: Duration = Duration::from_hours(1);
|
||||
|
||||
const NAME: &str = super::make_static_cache_header!(MA, SR);
|
||||
assert_eq!(
|
||||
NAME,
|
||||
format!(
|
||||
"public, max-age={}, stale-while-revalidate={}",
|
||||
MA.as_secs(),
|
||||
SR.as_secs()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user