Skip to content

Commit

Permalink
Add Age::from_secs
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Aug 7, 2020
1 parent f123396 commit 2e4771c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/cache/age.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ use std::time::Duration;
/// #
/// use http_types::Response;
/// use http_types::cache::Age;
/// use std::time::Duration;
///
/// let age = Age::new(Duration::from_secs(12));
/// let age = Age::from_secs(12);
///
/// let mut res = Response::new(200);
/// age.apply(&mut res);
///
/// let age = Age::from_headers(res)?.unwrap();
/// assert_eq!(age, Age::new(Duration::from_secs(12)));
/// assert_eq!(age, Age::from_secs(12));
/// #
/// # Ok(()) }
/// ```
Expand All @@ -41,6 +40,17 @@ impl Age {
Self { dur }
}

/// Create a new instance of `Age` from secs.
pub fn from_secs(secs: u64) -> Self {
let dur = Duration::from_secs(secs);
Self { dur }
}

/// Get the duration from the header.
pub fn duration(&self) -> Duration {
self.dur
}

/// Create an instance of `Age` from a `Headers` instance.
///
/// # Implementation note
Expand Down
4 changes: 2 additions & 2 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
//! - [MDN: HTTP Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching)
//! - [MDN: HTTP Conditional Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests)

mod cache_control;
mod age;
mod cache_control;

pub use age::Age;
pub use cache_control::CacheControl;
pub use cache_control::CacheDirective;
pub use age::Age;

0 comments on commit 2e4771c

Please sign in to comment.