Struct CacheControl

Source
pub struct CacheControl {
    pub cachability: Option<Cachability>,
    pub max_age: Option<Duration>,
    pub s_max_age: Option<Duration>,
    pub max_stale: Option<Duration>,
    pub min_fresh: Option<Duration>,
    pub must_revalidate: bool,
    pub proxy_revalidate: bool,
    pub immutable: bool,
    pub no_store: bool,
    pub no_transform: bool,
}
Expand description

Represents a Cache-Control header

Fields§

§cachability: Option<Cachability>§max_age: Option<Duration>

The maximum amount of time a resource is considered fresh. Unlike Expires, this directive is relative to the time of the request.

§s_max_age: Option<Duration>

Overrides max-age or the Expires header, but only for shared caches (e.g., proxies). Ignored by private caches.

§max_stale: Option<Duration>

Indicates the client will accept a stale response. An optional value in seconds indicates the upper limit of staleness the client will accept.

§min_fresh: Option<Duration>

Indicates the client wants a response that will still be fresh for at least the specified number of seconds.

§must_revalidate: bool

Indicates that once a resource becomes stale, caches do not use their stale copy without successful validation on the origin server.

§proxy_revalidate: bool

Like must-revalidate, but only for shared caches (e.g., proxies). Ignored by private caches.

§immutable: bool

Indicates that the response body will not change over time.

§no_store: bool

The response may not be stored in any cache.

§no_transform: bool

An intermediate cache or proxy cannot edit the response body, Content-Encoding, Content-Range, or Content-Type.

Implementations§

Source§

impl CacheControl

Source

pub fn from_value(value: &str) -> Option<Self>

Parses the value of the Cache-Control header (i.e. everything after “Cache-Control:”).

use cache_control::{Cachability, CacheControl};
use std::time::Duration;

let cache_control = CacheControl::from_value("public, max-age=60").unwrap();
assert_eq!(cache_control.cachability, Some(Cachability::Public));
assert_eq!(cache_control.max_age, Some(Duration::from_secs(60)));
Source

pub fn from_header(value: &str) -> Option<Self>

Parses a Cache-Control header.

Trait Implementations§

Source§

impl Debug for CacheControl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheControl

Source§

fn default() -> CacheControl

Returns the “default value” for a type. Read more
Source§

impl PartialEq for CacheControl

Source§

fn eq(&self, other: &CacheControl) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CacheControl

Source§

impl StructuralPartialEq for CacheControl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.