1
+ use std:: time:: Duration ;
1
2
/// An HTTP `Cache-Control` directive.
2
3
#[ derive( Debug ) ]
3
4
pub enum CacheDirective {
5
+ /// The response body will not change over time.
4
6
Immutable ,
7
+ /// The maximum amount of time a resource is considered fresh.
5
8
MaxAge ( Duration ) ,
9
+ /// Indicates the client will accept a stale response.
6
10
MaxStale ( Option < Duration > ) ,
11
+ /// A response that will still be fresh for at least the specified duration.
7
12
MinFresh ( Duration ) ,
13
+ /// Once a response is stale, a fresh response must be retrieved.
8
14
MustRevalidate ,
15
+ /// The response may be cached, but must always be revalidated before being used.
9
16
NoCache ,
17
+ /// The response may not be cached.
10
18
NoStore ,
19
+ /// An intermediate cache or proxy cannot edit the response body,
20
+ /// Content-Encoding, Content-Range, or Content-Type.
11
21
NoTransform ,
22
+ /// Do not use the network for a response.
12
23
OnlyIfCached ,
24
+ /// The response may be stored only by a browser's cache, even if the
25
+ /// response is normally non-cacheable
13
26
Private ,
27
+ /// Like must-revalidate, but only for shared caches (e.g., proxies).
14
28
ProxyRevalidate ,
29
+ /// The response may be stored by any cache, even if the response is normally
30
+ /// non-cacheable.
15
31
Public ,
32
+ /// Overrides max-age or the Expires header, but only for shared caches.
16
33
SMaxAge ( Duration ) ,
34
+ /// The client will accept a stale response if retrieving a fresh one fails.
17
35
StaleIfError ( Duration ) ,
36
+ /// Indicates the client will accept a stale response, while asynchronously
37
+ /// checking in the background for a fresh one.
18
38
StaleWhileRevalidate ( Duration ) ,
19
39
}
20
40
21
41
impl CacheDirective {
22
42
/// Check whether this directive is valid in an HTTP request.
23
43
pub fn is_req ( & self ) -> bool {
24
- use Self :: * ;
44
+ use CacheDirective :: * ;
25
45
match self {
26
46
MaxAge ( _) | MaxStale ( _) | MinFresh ( _) | NoCache | NoStore | NoTransform
27
47
| OnlyIfCached => true ,
@@ -31,10 +51,19 @@ impl CacheDirective {
31
51
32
52
/// Check whether this directive is valid in an HTTP response.
33
53
pub fn is_res ( & self ) -> bool {
34
- use Self :: * ;
54
+ use CacheDirective :: * ;
35
55
match self {
36
- MustRevalidate | NoCache | NoStore | NoTransform | Public | Private
37
- | ProxyRevalidate | MaxAge ( _) | SMaxAge ( _) => true ,
56
+ MustRevalidate
57
+ | NoCache
58
+ | NoStore
59
+ | NoTransform
60
+ | Public
61
+ | Private
62
+ | ProxyRevalidate
63
+ | MaxAge ( _)
64
+ | SMaxAge ( _)
65
+ | StaleIfError ( _)
66
+ | StaleWhileRevalidate ( _) => true ,
38
67
_ => false ,
39
68
}
40
69
}
0 commit comments