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;
1818/// #
1919/// use http_types::Response;
2020/// use http_types::cache::Age;
21- /// use std::time::Duration;
2221///
23- /// let age = Age::new(Duration:: from_secs(12) );
22+ /// let age = Age::from_secs(12);
2423///
2524/// let mut res = Response::new(200);
2625/// age.apply(&mut res);
2726///
2827/// 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));
3029/// #
3130/// # Ok(()) }
3231/// ```
@@ -41,6 +40,17 @@ impl Age {
4140 Self { dur }
4241 }
4342
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+
4454 /// Create an instance of `Age` from a `Headers` instance.
4555 ///
4656 /// # Implementation note
Original file line number Diff line number Diff line change 99//! - [MDN: HTTP Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
1010//! - [MDN: HTTP Conditional Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests)
1111
12- mod cache_control;
1312mod age;
13+ mod cache_control;
1414
15+ pub use age:: Age ;
1516pub use cache_control:: CacheControl ;
1617pub use cache_control:: CacheDirective ;
17- pub use age:: Age ;
You can’t perform that action at this time.
0 commit comments