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§

source§

impl Headers

source

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

source

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.

source

pub fn get(&self, name: impl Into<HeaderName>) -> Option<&HeaderValues>

Get a reference to a header.

source

pub fn get_mut( &mut self, name: impl Into<HeaderName> ) -> Option<&mut HeaderValues>

Get a mutable reference to a header.

source

pub fn remove(&mut self, name: impl Into<HeaderName>) -> Option<HeaderValues>

Remove a header.

source

pub fn iter(&self) -> Iter<'_>

An iterator visiting all header pairs in arbitrary order.

source

pub fn iter_mut(&mut self) -> IterMut<'_>

An iterator visiting all header pairs in arbitrary order, with mutable references to the values.

source

pub fn names(&self) -> Names<'_>

An iterator visiting all header names in arbitrary order.

source

pub fn values(&self) -> Values<'_>

An iterator visiting all header values in arbitrary order.

Trait Implementations§

source§

impl AsMut<Headers> for Headers

source§

fn as_mut(&mut self) -> &mut Headers

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsMut<Headers> for Request

source§

fn as_mut(&mut self) -> &mut Headers

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsMut<Headers> for Response

source§

fn as_mut(&mut self) -> &mut Headers

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Headers> for Headers

source§

fn as_ref(&self) -> &Headers

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Headers> for Request

source§

fn as_ref(&self) -> &Headers

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Headers> for Response

source§

fn as_ref(&self) -> &Headers

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Headers

source§

fn clone(&self) -> Headers

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Headers

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Index<&str> for Headers

source§

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

The returned type after indexing.
source§

impl Index<HeaderName> for Headers

source§

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

The returned type after indexing.
source§

impl<'a> IntoIterator for &'a Headers

§

type Item = (&'a HeaderName, &'a HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Headers

§

type Item = (&'a HeaderName, &'a mut HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Headers

source§

fn into_iter(self) -> Self::IntoIter

Returns a iterator of references over the remaining items.

§

type Item = (HeaderName, HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more