pub struct Headers { /* private fields */ }
Expand description
A map of header fields on requests and responses.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn with_capacity(len: usize) -> Headers
pub fn with_capacity(len: usize) -> Headers
Creates a new Headers
struct with space reserved for len
headers.
Sourcepub fn set<H: Header>(&mut self, value: H)
pub fn set<H: Header>(&mut self, value: H)
Set a header field to the corresponding value.
The field is determined by the type of the value being set.
Sourcepub fn get<H: Header>(&self) -> Option<&H>
pub fn get<H: Header>(&self) -> Option<&H>
Get a reference to the header field’s value, if it exists.
Sourcepub fn get_mut<H: Header>(&mut self) -> Option<&mut H>
pub fn get_mut<H: Header>(&mut self) -> Option<&mut H>
Get a mutable reference to the header field’s value, if it exists.
Sourcepub fn has<H: Header>(&self) -> bool
pub fn has<H: Header>(&self) -> bool
Returns a boolean of whether a certain header is in the map.
Example:
headers.set(ContentType::json());
assert!(headers.has::<ContentType>());
Sourcepub fn remove<H: Header>(&mut self) -> Option<H>
pub fn remove<H: Header>(&mut self) -> Option<H>
Removes a header from the map, if one existed. Returns the header, if one has been removed and could be parsed.
Note that this function may return None
even though a header was removed. If you want to
know whether a header exists, rather rely on has
.
Sourcepub fn iter(&self) -> HeadersItems<'_> ⓘ
pub fn iter(&self) -> HeadersItems<'_> ⓘ
Returns an iterator over the header fields.
Sourcepub fn get_raw(&self, name: &str) -> Option<&Raw>
pub fn get_raw(&self, name: &str) -> Option<&Raw>
Access the raw value of a header.
Prefer to use the typed getters instead.
Example:
let raw = headers.get_raw("content-type").unwrap();
assert_eq!(raw, "text/plain");
Sourcepub fn set_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>(
&mut self,
name: K,
value: V,
)
pub fn set_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>( &mut self, name: K, value: V, )
Set the raw value of a header, bypassing any typed headers.
Example:
headers.set_raw("content-length", b"1".as_ref());
headers.set_raw("content-length", "2");
headers.set_raw("content-length", "3".to_string());
headers.set_raw("content-length", vec![vec![b'4']]);
Sourcepub fn append_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>(
&mut self,
name: K,
value: V,
)
pub fn append_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>( &mut self, name: K, value: V, )
Append a value to raw value of this header.
If a header already contains a value, this will add another line to it.
If a header does not exist for this name, a new one will be created with the value.
Example:
headers.append_raw("x-foo", b"bar".to_vec());
headers.append_raw("x-foo", b"quux".to_vec());
Sourcepub fn remove_raw(&mut self, name: &str)
pub fn remove_raw(&mut self, name: &str)
Remove a header by name.
Trait Implementations§
Source§impl<'a> Extend<(&'a str, Bytes)> for Headers
impl<'a> Extend<(&'a str, Bytes)> for Headers
Source§fn extend<I: IntoIterator<Item = (&'a str, Bytes)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (&'a str, Bytes)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<HeaderView<'a>> for Headers
impl<'a> Extend<HeaderView<'a>> for Headers
Source§fn extend<I: IntoIterator<Item = HeaderView<'a>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = HeaderView<'a>>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> FromIterator<HeaderView<'a>> for Headers
impl<'a> FromIterator<HeaderView<'a>> for Headers
Source§fn from_iter<I: IntoIterator<Item = HeaderView<'a>>>(iter: I) -> Headers
fn from_iter<I: IntoIterator<Item = HeaderView<'a>>>(iter: I) -> 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 !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,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)