File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,14 @@ use std::time::Duration;
18
18
/// #
19
19
/// use http_types::Response;
20
20
/// use http_types::cache::Age;
21
- /// use std::time::Duration;
22
21
///
23
- /// let age = Age::new(Duration:: from_secs(12) );
22
+ /// let age = Age::from_secs(12);
24
23
///
25
24
/// let mut res = Response::new(200);
26
25
/// age.apply(&mut res);
27
26
///
28
27
/// let age = Age::from_headers(res)?.unwrap();
29
- /// assert_eq!(age, Age::new(Duration:: from_secs(12) ));
28
+ /// assert_eq!(age, Age::from_secs(12));
30
29
/// #
31
30
/// # Ok(()) }
32
31
/// ```
@@ -41,6 +40,17 @@ impl Age {
41
40
Self { dur }
42
41
}
43
42
43
+ /// Create a new instance of `Age` from secs.
44
+ pub fn from_secs ( secs : u64 ) -> Self {
45
+ let dur = Duration :: from_secs ( secs) ;
46
+ Self { dur }
47
+ }
48
+
49
+ /// Get the duration from the header.
50
+ pub fn duration ( & self ) -> Duration {
51
+ self . dur
52
+ }
53
+
44
54
/// Create an instance of `Age` from a `Headers` instance.
45
55
///
46
56
/// # Implementation note
Original file line number Diff line number Diff line change 9
9
//! - [MDN: HTTP Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
10
10
//! - [MDN: HTTP Conditional Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests)
11
11
12
- mod cache_control;
13
12
mod age;
13
+ mod cache_control;
14
14
15
+ pub use age:: Age ;
15
16
pub use cache_control:: CacheControl ;
16
17
pub use cache_control:: CacheDirective ;
17
- pub use age:: Age ;
You can’t perform that action at this time.
0 commit comments