#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct CacheControl {
pub public: bool,
pub max_age: usize,
}
impl Default for CacheControl {
fn default() -> Self {
Self {
public: true,
max_age: 0,
}
}
}
impl CacheControl {
#[must_use]
pub fn value(&self) -> Option<String> {
if self.max_age > 0 {
Some(format!(
"max-age={}{}",
self.max_age,
if self.public { "" } else { ", private" }
))
} else {
None
}
}
}
impl CacheControl {
pub(crate) fn merge(&mut self, other: &CacheControl) {
self.public = self.public && other.public;
self.max_age = if self.max_age == 0 {
other.max_age
} else if other.max_age == 0 {
self.max_age
} else {
self.max_age.min(other.max_age)
};
}
}