pub struct CacheControl {
pub directives: DirectiveMap,
pub allow_float_seconds: bool,
}Expand description
Parsed Cache-Control directives
Fields§
§directives: DirectiveMapThe parsed directives
allow_float_seconds: boolWhen set, delta-seconds directives (max-age, s-maxage,
stale-while-revalidate, stale-if-error) accept fractional values
and round them down to the nearest non-negative integer.
Defaults to false, matching RFC 9111 strict integer parsing. Enable
via CacheControl::with_float_seconds (or by assigning the field
directly) for contexts that need to interoperate with upstreams that
emit fractional ttls.
Implementations§
Source§impl CacheControl
impl CacheControl
Sourcepub fn with_float_seconds(self) -> Self
pub fn with_float_seconds(self) -> Self
Builder setter: enable fractional delta-seconds parsing.
See CacheControl::allow_float_seconds for semantics. Returns self
so it can be chained onto a parser call, e.g.
CacheControl::from_resp_headers(&resp).map(|cc| cc.with_float_seconds()).
Sourcepub fn from_headers_named(
header_name: &str,
headers: &HeaderMap,
) -> Option<Self>
pub fn from_headers_named( header_name: &str, headers: &HeaderMap, ) -> Option<Self>
Parse from the given header name in headers
Sourcepub fn from_req_headers_named(
header_name: &str,
req_header: &ReqHeader,
) -> Option<Self>
pub fn from_req_headers_named( header_name: &str, req_header: &ReqHeader, ) -> Option<Self>
Parse from the given header name in the ReqHeader
Sourcepub fn from_req_headers(req_header: &ReqHeader) -> Option<Self>
pub fn from_req_headers(req_header: &ReqHeader) -> Option<Self>
Parse Cache-Control header name from the ReqHeader
Sourcepub fn from_resp_headers_named(
header_name: &str,
resp_header: &RespHeader,
) -> Option<Self>
pub fn from_resp_headers_named( header_name: &str, resp_header: &RespHeader, ) -> Option<Self>
Parse from the given header name in the RespHeader
Sourcepub fn from_resp_headers(resp_header: &RespHeader) -> Option<Self>
pub fn from_resp_headers(resp_header: &RespHeader) -> Option<Self>
Parse Cache-Control header name from the RespHeader
Sourcepub fn has_key(&self, key: &str) -> bool
pub fn has_key(&self, key: &str) -> bool
Whether the given directive is in the cache control.
Accepts a string for convenience; known directive names are matched
without allocation. Prefer has_directive when
you already have a DirectiveKey.
Note: key must already be lowercase (e.g. "max-age", not
"Max-Age"). Directive names are stored in wire-format lowercase;
a mixed-case input will silently miss.
Sourcepub fn has_directive(&self, key: &DirectiveKey) -> bool
pub fn has_directive(&self, key: &DirectiveKey) -> bool
Whether the given DirectiveKey is in the cache control.
Sourcepub fn private_field_names(&self) -> Option<ListValueIter<'_>>
pub fn private_field_names(&self) -> Option<ListValueIter<'_>>
Get the values of private=
Sourcepub fn no_cache_field_names(&self) -> Option<ListValueIter<'_>>
pub fn no_cache_field_names(&self) -> Option<ListValueIter<'_>>
Get the values of no-cache=
Sourcepub fn stale_while_revalidate(&self) -> Result<Option<u32>>
pub fn stale_while_revalidate(&self) -> Result<Option<u32>>
Return the stale-while-revalidate seconds
Sourcepub fn stale_if_error(&self) -> Result<Option<u32>>
pub fn stale_if_error(&self) -> Result<Option<u32>>
Return the stale-if-error seconds
Sourcepub fn must_revalidate(&self) -> bool
pub fn must_revalidate(&self) -> bool
Whether must-revalidate exists.
Sourcepub fn proxy_revalidate(&self) -> bool
pub fn proxy_revalidate(&self) -> bool
Whether proxy-revalidate exists.
Sourcepub fn only_if_cached(&self) -> bool
pub fn only_if_cached(&self) -> bool
Whether only-if-cached exists.
Trait Implementations§
Source§impl Debug for CacheControl
impl Debug for CacheControl
Source§impl InterpretCacheControl for CacheControl
impl InterpretCacheControl for CacheControl
Source§fn is_cacheable(&self) -> Cacheable
fn is_cacheable(&self) -> Cacheable
Source§fn fresh_duration(&self) -> Option<Duration>
fn fresh_duration(&self) -> Option<Duration>
Source§fn serve_stale_while_revalidate_duration(&self) -> Option<Duration>
fn serve_stale_while_revalidate_duration(&self) -> Option<Duration>
Source§fn serve_stale_if_error_duration(&self) -> Option<Duration>
fn serve_stale_if_error_duration(&self) -> Option<Duration>
Source§fn strip_private_headers(&self, resp_header: &mut ResponseHeader)
fn strip_private_headers(&self, resp_header: &mut ResponseHeader)
private or no-cache directives from a response,
usually prior to storing that response in cache.