Struct headers::common::cache_control::CacheControl

source ·
pub struct CacheControl {
    flags: Flags,
    max_age: Option<Seconds>,
    max_stale: Option<Seconds>,
    min_fresh: Option<Seconds>,
    s_max_age: Option<Seconds>,
}
Expand description

Cache-Control header, defined in RFC7234 with extensions in RFC8246

The Cache-Control header field is used to specify directives for caches along the request/response chain. Such cache directives are unidirectional in that the presence of a directive in a request does not imply that the same directive is to be given in the response.

§ABNF

Cache-Control   = 1#cache-directive
cache-directive = token [ "=" ( token / quoted-string ) ]

§Example values

  • no-cache
  • private, community="UCI"
  • max-age=30

§Example

use headers::CacheControl;

let cc = CacheControl::new();

Fields§

§flags: Flags§max_age: Option<Seconds>§max_stale: Option<Seconds>§min_fresh: Option<Seconds>§s_max_age: Option<Seconds>

Implementations§

source§

impl CacheControl

source

pub fn new() -> Self

Construct a new empty CacheControl header.

source

pub fn no_cache(&self) -> bool

Check if the no-cache directive is set.

source

pub fn no_store(&self) -> bool

Check if the no-store directive is set.

source

pub fn no_transform(&self) -> bool

Check if the no-transform directive is set.

source

pub fn only_if_cached(&self) -> bool

Check if the only-if-cached directive is set.

source

pub fn public(&self) -> bool

Check if the public directive is set.

source

pub fn private(&self) -> bool

Check if the private directive is set.

source

pub fn immutable(&self) -> bool

Check if the immutable directive is set.

source

pub fn max_age(&self) -> Option<Duration>

Get the value of the max-age directive if set.

source

pub fn max_stale(&self) -> Option<Duration>

Get the value of the max-stale directive if set.

source

pub fn min_fresh(&self) -> Option<Duration>

Get the value of the min-fresh directive if set.

source

pub fn s_max_age(&self) -> Option<Duration>

Get the value of the s-maxage directive if set.

source

pub fn with_no_cache(self) -> Self

Set the no-cache directive.

source

pub fn with_no_store(self) -> Self

Set the no-store directive.

source

pub fn with_no_transform(self) -> Self

Set the no-transform directive.

source

pub fn with_only_if_cached(self) -> Self

Set the only-if-cached directive.

source

pub fn with_private(self) -> Self

Set the private directive.

source

pub fn with_public(self) -> Self

Set the public directive.

source

pub fn with_immutable(self) -> Self

Set the immutable directive.

source

pub fn with_max_age(self, duration: Duration) -> Self

Set the max-age directive.

source

pub fn with_max_stale(self, duration: Duration) -> Self

Set the max-stale directive.

source

pub fn with_min_fresh(self, duration: Duration) -> Self

Set the min-fresh directive.

source

pub fn with_s_max_age(self, duration: Duration) -> Self

Set the s-maxage directive.

Trait Implementations§

source§

impl Clone for CacheControl

source§

fn clone(&self) -> CacheControl

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CacheControl

source§

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

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

impl Header for CacheControl

source§

fn name() -> &'static HeaderName

The name of this header.
source§

fn decode<'i, I: Iterator<Item = &'i HeaderValue>>( values: &mut I, ) -> Result<Self, Error>

Decode this type from an iterator of HeaderValues.
source§

fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)

Encode this type to a HeaderMap. 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 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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.