pub struct Headers(/* private fields */);Expand description
Request or response headers.
A thin wrapper around http::HeaderMap that adds provider-oriented
helpers: overriding merge, user-agent suffixing and masking of sensitive
values in diagnostic output. Debug and Serialize never reveal
authorization, API-key or cookie values.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn as_map_mut(&mut self) -> &mut HeaderMap
pub fn as_map_mut(&mut self) -> &mut HeaderMap
Returns the wrapped HeaderMap mutably.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of header entries (repeated names count once each).
Sourcepub fn get_str(&self, name: &str) -> Option<&str>
pub fn get_str(&self, name: &str) -> Option<&str>
Returns the first value of name as a string, if present and ASCII.
Sourcepub fn insert(&mut self, name: &str, value: &str) -> Result<(), InvalidHeader>
pub fn insert(&mut self, name: &str, value: &str) -> Result<(), InvalidHeader>
Inserts a header, replacing existing values with the same name.
Returns an error when the name or value is not a valid header.
§Errors
Returns InvalidHeader when name is not a valid header name or
value contains characters not allowed in header values.
Sourcepub fn with(self, name: &str, value: &str) -> Self
pub fn with(self, name: &str, value: &str) -> Self
Builder-style Headers::insert; invalid pairs are skipped silently.
Intended for static configuration where the caller controls the values;
use Headers::insert for untrusted input.
Sourcepub fn merge(&mut self, other: &Headers)
pub fn merge(&mut self, other: &Headers)
Merges other into self; values in other override existing ones.
Repeated header names in other replace all existing values of that
name, mirroring “later headers win” semantics for configuration
layering (provider defaults, per-model settings, per-call headers).
Sourcepub fn merged(self, other: &Headers) -> Self
pub fn merged(self, other: &Headers) -> Self
Returns a copy with other merged on top; see Headers::merge.
Sourcepub fn merge_pairs<'a, I>(&mut self, pairs: I)
pub fn merge_pairs<'a, I>(&mut self, pairs: I)
Merges optional string pairs; pairs whose value is None are skipped.
Invalid names or values are skipped as well; this mirrors the lenient behaviour needed when layering user-supplied header maps.
Sourcepub fn with_user_agent_suffix<'a, I>(self, suffixes: I) -> Selfwhere
I: IntoIterator<Item = &'a str>,
pub fn with_user_agent_suffix<'a, I>(self, suffixes: I) -> Selfwhere
I: IntoIterator<Item = &'a str>,
Appends suffixes to the user-agent header, creating it if absent.
Existing user-agent text is kept and each suffix is separated by a single space. Empty suffixes are ignored.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Headers
Deserializes from an object of name -> value pairs; invalid entries are
rejected with an error.
impl<'de> Deserialize<'de> for Headers
Deserializes from an object of name -> value pairs; invalid entries are
rejected with an error.
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Headers
Source§impl<'a> IntoIterator for &'a Headers
impl<'a> IntoIterator for &'a Headers
Source§type Item = (&'a HeaderName, &'a HeaderValue)
type Item = (&'a HeaderName, &'a HeaderValue)
Source§type IntoIter = Iter<'a, HeaderValue>
type IntoIter = Iter<'a, HeaderValue>
Source§impl Serialize for Headers
Serializes as an object of name -> value pairs with sensitive values
masked. Repeated header names are joined with ", ".
impl Serialize for Headers
Serializes as an object of name -> value pairs with sensitive values
masked. Repeated header names are joined with ", ".
impl StructuralPartialEq for Headers
Auto Trait Implementations§
impl Freeze for Headers
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnsafeUnpin for Headers
impl UnwindSafe for Headers
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.