Struct ajars_surf::surf::http::Headers
[−]pub struct Headers { /* private fields */ }
Expand description
A collection of HTTP Headers.
Headers are never manually constructed, but are part of Request
,
Response
, and Trailers
. Each of these types implements AsRef<Headers>
and AsMut<Headers>
so functions that want to modify headers can be generic
over either of these traits.
Examples
use http_types::{Response, StatusCode};
let mut res = Response::new(StatusCode::Ok);
res.insert_header("hello", "foo0");
assert_eq!(res["hello"], "foo0");
Implementations
impl Headers
impl Headers
pub fn insert(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Option<HeaderValues>
pub fn insert(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Option<HeaderValues>
Insert a header into the headers.
Not that this will replace all header values for a given header name.
If you wish to add header values for a header name that already exists
use Headers::append
pub fn append(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
)
pub fn append(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
)
Append a header to the headers.
Unlike insert
this function will not override the contents of a header, but insert a
header if there aren’t any. Or else append to the existing list of headers.
pub fn get(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>
pub fn get(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>
Get a reference to a header.
pub fn get_mut(
&mut self,
name: impl Into<HeaderName>
) -> Option<&mut HeaderValues>
pub fn get_mut(
&mut self,
name: impl Into<HeaderName>
) -> Option<&mut HeaderValues>
Get a mutable reference to a header.
pub fn remove(&mut self, name: impl Into<HeaderName>) -> Option<HeaderValues>
pub fn remove(&mut self, name: impl Into<HeaderName>) -> Option<HeaderValues>
Remove a header.
pub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = (&'a HeaderName, &'a HeaderValues);
pub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = (&'a HeaderName, &'a HeaderValues);
An iterator visiting all header pairs in arbitrary order.
pub fn iter_mut(&mut self) -> IterMut<'_>ⓘNotable traits for IterMut<'a>impl<'a> Iterator for IterMut<'a> type Item = (&'a HeaderName, &'a mut HeaderValues);
pub fn iter_mut(&mut self) -> IterMut<'_>ⓘNotable traits for IterMut<'a>impl<'a> Iterator for IterMut<'a> type Item = (&'a HeaderName, &'a mut HeaderValues);
An iterator visiting all header pairs in arbitrary order, with mutable references to the values.
Trait Implementations
impl<'_> Index<&'_ str> for Headers
impl<'_> Index<&'_ str> for Headers
fn index(&self, name: &str) -> &HeaderValues
fn index(&self, name: &str) -> &HeaderValues
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Headers
.
type Output = HeaderValues
type Output = HeaderValues
The returned type after indexing.
impl Index<HeaderName> for Headers
impl Index<HeaderName> for Headers
fn index(&self, name: HeaderName) -> &HeaderValues
fn index(&self, name: HeaderName) -> &HeaderValues
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Headers
.
type Output = HeaderValues
type Output = HeaderValues
The returned type after indexing.
impl IntoIterator for Headers
impl IntoIterator for Headers
fn into_iter(self) -> <Headers as IntoIterator>::IntoIter
fn into_iter(self) -> <Headers as IntoIterator>::IntoIter
Returns a iterator of references over the remaining items.
type Item = (HeaderName, HeaderValues)
type Item = (HeaderName, HeaderValues)
The type of the elements being iterated over.
impl<'a> IntoIterator for &'a mut Headers
impl<'a> IntoIterator for &'a mut Headers
type Item = (&'a HeaderName, &'a mut HeaderValues)
type Item = (&'a HeaderName, &'a mut HeaderValues)
The type of the elements being iterated over.
fn into_iter(self) -> <&'a mut Headers as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a mut Headers as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
impl<'a> IntoIterator for &'a Headers
impl<'a> IntoIterator for &'a Headers
type Item = (&'a HeaderName, &'a HeaderValues)
type Item = (&'a HeaderName, &'a HeaderValues)
The type of the elements being iterated over.
fn into_iter(self) -> <&'a Headers as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a Headers as IntoIterator>::IntoIter
Creates an iterator from a value. Read more
Auto Trait Implementations
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnwindSafe for Headers
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more