pub struct Headers { /* private fields */ }Expand description
An ordered, case-insensitive header list.
Implementations§
Source§impl Headers
impl Headers
pub fn new() -> Self
Sourcepub fn from_pairs(entries: Vec<(String, String)>) -> Self
pub fn from_pairs(entries: Vec<(String, String)>) -> Self
Build from an ordered (name, value) list verbatim (duplicates and
casing preserved) — the shape reqwest response headers arrive in.
Sourcepub fn get(&self, name: &str) -> Option<String>
pub fn get(&self, name: &str) -> Option<String>
WHATWG combined value: all same-name values joined with ,
(\n for set-cookie). None when the header is absent.
Sourcepub fn get_first(&self, name: &str) -> Option<&str>
pub fn get_first(&self, name: &str) -> Option<&str>
The first value for name, uncombined (case-insensitive).
Sourcepub fn get_all(&self, name: &str) -> Vec<&str>
pub fn get_all(&self, name: &str) -> Vec<&str>
Every value stored under name, in insertion order.
The Set-Cookie values, kept individually (WHATWG getSetCookie).
pub fn contains(&self, name: &str) -> bool
Sourcepub fn set(&mut self, name: &str, value: impl Into<String>)
pub fn set(&mut self, name: &str, value: impl Into<String>)
Replace every value for name with a single value (WHATWG
set). The first slot keeps its position; later duplicates drop.
Sourcepub fn set_if_absent(&mut self, name: &str, value: impl Into<String>)
pub fn set_if_absent(&mut self, name: &str, value: impl Into<String>)
Set name to value only if it is not already present.
Sourcepub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)
Append a value under name without removing existing ones (WHATWG
append).
Sourcepub fn append_combined(&mut self, name_lc: String, value: String)
pub fn append_combined(&mut self, name_lc: String, value: String)
WHATWG “append”, as the JS Headers class exposes it: set-cookie
is never combined and stays a separate entry; every other repeat
joins the existing value with , in place. name_lc must already
be lowercased and value normalized.
Sourcepub fn get_joined(&self, name: &str) -> Option<String>
pub fn get_joined(&self, name: &str) -> Option<String>
Combined value of name joined with , for EVERY header,
set-cookie included — what the WHATWG Headers.get() returns.
Self::get differs deliberately: it splits set-cookie with
\n to match Playwright’s RawHeaders.
Sourcepub fn sorted_entries(&self) -> Vec<(String, String)>
pub fn sorted_entries(&self) -> Vec<(String, String)>
The entries sorted by name — the order the WHATWG Headers
iterators yield. The sort is stable, so repeated set-cookie
entries keep insertion order.
Sourcepub fn iter(&self) -> impl Iterator<Item = &(String, String)>
pub fn iter(&self) -> impl Iterator<Item = &(String, String)>
Iterate the (name, value) entries in insertion order.
pub fn entries(&self) -> &[(String, String)]
pub fn into_pairs(self) -> Vec<(String, String)>
Sourcepub fn to_object(&self) -> Vec<(String, String)>
pub fn to_object(&self) -> Vec<(String, String)>
Flattened header object: lowercased names, each mapped to its
combined value, ordered by first appearance. Playwright’s
RawHeaders.headers() (client/network.ts:959), which backs
apiResponse.headers().