pub struct Expires { /* private fields */ }
Expand description
HTTP Expires
header
§Specifications
§Examples
use http_types::Response;
use http_types::cache::Expires;
use std::time::{SystemTime, Duration};
let time = SystemTime::now() + Duration::from_secs(5 * 60);
let expires = Expires::new_at(time);
let mut res = Response::new(200);
expires.apply(&mut res);
let expires = Expires::from_headers(res)?.unwrap();
// HTTP dates only have second-precision.
let elapsed = time.duration_since(expires.expiration())?;
assert_eq!(elapsed.as_secs(), 0);
Implementations§
Source§impl Expires
impl Expires
Sourcepub fn new_at(instant: SystemTime) -> Self
pub fn new_at(instant: SystemTime) -> Self
Create a new instance of Expires
from secs.
Sourcepub fn expiration(&self) -> SystemTime
pub fn expiration(&self) -> SystemTime
Get the expiration time.
Sourcepub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
pub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
Create an instance of Expires
from a Headers
instance.
Sourcepub fn apply(&self, headers: impl AsMut<Headers>)
pub fn apply(&self, headers: impl AsMut<Headers>)
Insert a HeaderName
+ HeaderValue
pair into a Headers
instance.
Sourcepub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName
.
Sourcepub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue
.
Trait Implementations§
Source§impl Ord for Expires
impl Ord for Expires
Source§impl PartialOrd for Expires
impl PartialOrd for Expires
Source§impl ToHeaderValues for Expires
impl ToHeaderValues for Expires
Source§type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
Source§fn to_header_values(&self) -> Result<Self::Iter>
fn to_header_values(&self) -> Result<Self::Iter>
Converts this object to an iterator of resolved
HeaderValues
.impl Eq for Expires
impl StructuralPartialEq for Expires
Auto Trait Implementations§
impl Freeze for Expires
impl RefUnwindSafe for Expires
impl Send for Expires
impl Sync for Expires
impl Unpin for Expires
impl UnwindSafe for Expires
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more