web_static_pack/
cache_control.rs

1//! Cache control related types. Provides [CacheControl].
2
3use crate::common::cache_control::{CacheControl as CacheControl_, CacheControlArchived};
4use http::HeaderValue;
5
6/// Cache control enumeration, used to generate `cache-control` header content.
7/// This will be usually built from [CacheControlArchived] or [CacheControl_]
8/// (via [From]).
9#[derive(Debug)]
10pub enum CacheControl {
11    /// Prevents caching file, by setting `no-cache` in `cache-control`.
12    NoCache,
13    /// Sets value to make resource cached for as long as possible.
14    MaxCache,
15}
16impl CacheControl {
17    /// Creates http [HeaderValue] from [self].
18    pub fn cache_control(&self) -> HeaderValue {
19        match self {
20            CacheControl::NoCache => HeaderValue::from_static("no-cache"),
21            CacheControl::MaxCache => HeaderValue::from_static("max-age=31536000, immutable"),
22        }
23    }
24}
25impl From<CacheControl_> for CacheControl {
26    fn from(value: CacheControl_) -> Self {
27        match value {
28            CacheControl_::NoCache => Self::NoCache,
29            CacheControl_::MaxCache => Self::MaxCache,
30        }
31    }
32}
33impl From<CacheControlArchived> for CacheControl {
34    fn from(value: CacheControlArchived) -> Self {
35        match value {
36            CacheControlArchived::NoCache => Self::NoCache,
37            CacheControlArchived::MaxCache => Self::MaxCache,
38        }
39    }
40}