1+ use std:: time:: Duration ;
12/// An HTTP `Cache-Control` directive.
23#[ derive( Debug ) ]
34pub enum CacheDirective {
5+ /// The response body will not change over time.
46 Immutable ,
7+ /// The maximum amount of time a resource is considered fresh.
58 MaxAge ( Duration ) ,
9+ /// Indicates the client will accept a stale response.
610 MaxStale ( Option < Duration > ) ,
11+ /// A response that will still be fresh for at least the specified duration.
712 MinFresh ( Duration ) ,
13+ /// Once a response is stale, a fresh response must be retrieved.
814 MustRevalidate ,
15+ /// The response may be cached, but must always be revalidated before being used.
916 NoCache ,
17+ /// The response may not be cached.
1018 NoStore ,
19+ /// An intermediate cache or proxy cannot edit the response body,
20+ /// Content-Encoding, Content-Range, or Content-Type.
1121 NoTransform ,
22+ /// Do not use the network for a response.
1223 OnlyIfCached ,
24+ /// The response may be stored only by a browser's cache, even if the
25+ /// response is normally non-cacheable
1326 Private ,
27+ /// Like must-revalidate, but only for shared caches (e.g., proxies).
1428 ProxyRevalidate ,
29+ /// The response may be stored by any cache, even if the response is normally
30+ /// non-cacheable.
1531 Public ,
32+ /// Overrides max-age or the Expires header, but only for shared caches.
1633 SMaxAge ( Duration ) ,
34+ /// The client will accept a stale response if retrieving a fresh one fails.
1735 StaleIfError ( Duration ) ,
36+ /// Indicates the client will accept a stale response, while asynchronously
37+ /// checking in the background for a fresh one.
1838 StaleWhileRevalidate ( Duration ) ,
1939}
2040
2141impl CacheDirective {
2242 /// Check whether this directive is valid in an HTTP request.
2343 pub fn is_req ( & self ) -> bool {
24- use Self :: * ;
44+ use CacheDirective :: * ;
2545 match self {
2646 MaxAge ( _) | MaxStale ( _) | MinFresh ( _) | NoCache | NoStore | NoTransform
2747 | OnlyIfCached => true ,
@@ -31,10 +51,19 @@ impl CacheDirective {
3151
3252 /// Check whether this directive is valid in an HTTP response.
3353 pub fn is_res ( & self ) -> bool {
34- use Self :: * ;
54+ use CacheDirective :: * ;
3555 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 ,
3867 _ => false ,
3968 }
4069 }
0 commit comments