Skip to content

Commit 79a7c5f

Browse files
committed
init cache control
1 parent a50b9b9 commit 79a7c5f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/cache/cache_control.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/// An HTTP `Cache-Control` directive.
2+
#[derive(Debug)]
3+
pub enum CacheDirective {
4+
Immutable,
5+
MaxAge(Duration),
6+
MaxStale(Option<Duration>),
7+
MinFresh(Duration),
8+
MustRevalidate,
9+
NoCache,
10+
NoStore,
11+
NoTransform,
12+
OnlyIfCached,
13+
Private,
14+
ProxyRevalidate,
15+
Public,
16+
SMaxAge(Duration),
17+
StaleIfError(Duration),
18+
StaleWhileRevalidate(Duration),
19+
}
20+
21+
impl CacheDirective {
22+
/// Check whether this directive is valid in an HTTP request.
23+
pub fn is_req(&self) -> bool {
24+
use Self::*;
25+
match self {
26+
MaxAge(_) | MaxStale(_) | MinFresh(_) | NoCache | NoStore | NoTransform
27+
| OnlyIfCached => true,
28+
_ => false,
29+
}
30+
}
31+
32+
/// Check whether this directive is valid in an HTTP response.
33+
pub fn is_res(&self) -> bool {
34+
use Self::*;
35+
match self {
36+
MustRevalidate | NoCache | NoStore | NoTransform | Public | Private
37+
| ProxyRevalidate | MaxAge(_) | SMaxAge(_) => true,
38+
_ => false,
39+
}
40+
}
41+
}

src/cache/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod cache_control;

0 commit comments

Comments
 (0)