pub enum Vary {
Wildcard,
Headers(Vec<String>),
}Expand description
The Vary response header (RFC 7231 §7.1.4).
Encodes the set of request header field names that were used to select the
representation. The special value * means any request header may affect
the response.
Variants§
Wildcard
Vary: * — response is uncacheable by shared caches.
Headers(Vec<String>)
Vary: <header-name>, ... — a specific list of header names.
Implementations§
Source§impl Vary
impl Vary
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Returns true if this is the wildcard variant.
Sourcepub fn headers(&self) -> Option<&[String]>
pub fn headers(&self) -> Option<&[String]>
Returns the list of header names, or None if this is a wildcard.
Sourcepub fn add(&mut self, name: impl Into<String>)
pub fn add(&mut self, name: impl Into<String>)
Add a header name to the Vary list.
If self is Vary::Wildcard this is a no-op. Duplicate names
(case-insensitive) are not added a second time.
use api_bones::vary::Vary;
let mut v = Vary::new();
v.add("Accept");
v.add("accept"); // duplicate — ignored
assert_eq!(v.to_string(), "Accept");Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Remove a header name from the Vary list (case-insensitive).
Returns true if the name was present and removed. Always returns
false for the wildcard variant.
use api_bones::vary::Vary;
let mut v = Vary::new();
v.add("Accept");
assert!(v.remove("ACCEPT"));
assert_eq!(v.to_string(), "");Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true if the named header is in the Vary list
(case-insensitive).
Always returns false for the wildcard variant.
use api_bones::vary::Vary;
let mut v = Vary::new();
v.add("Accept-Encoding");
assert!(v.contains("accept-encoding"));
assert!(!v.contains("accept"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Vary
impl<'de> Deserialize<'de> for Vary
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromStr for Vary
impl FromStr for Vary
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a Vary header value.
use api_bones::vary::Vary;
let v: Vary = "*".parse().unwrap();
assert!(v.is_wildcard());
let v: Vary = "Accept, Accept-Encoding".parse().unwrap();
assert!(v.contains("Accept-Encoding"));