use crate::{internet::AsHeaderField, util::raw_string::ToInt};
pub struct CacheControl {
pub no_cache: bool,
pub max_age: u32,
}
pub fn parse(s: &[u8]) -> CacheControl {
let mut cc = CacheControl {
no_cache: true,
max_age: 0,
};
let header_field = s.as_header_field();
let iter = header_field.get_parameter_iterator();
for param in iter {
if param.name.eq_ignore_ascii_case(b"no-cache") {
cc.no_cache = true;
} else if param.name.eq_ignore_ascii_case(b"max-age") {
if let Some(max_age) = param.value {
if let Ok(max_age) = max_age.to_int::<u32>() {
cc.max_age = max_age;
}
}
}
}
cc
}