Struct trillium_http::Headers

source ·
pub struct Headers { /* private fields */ }
Expand description

Trillium’s header map type

Implementations§

source§

impl Headers

source

pub fn with_capacity(capacity: usize) -> Self

Construct a new Headers, expecting to see at least this many known headers.

source

pub fn new() -> Self

Construct a new headers with a default capacity of 15 known headers

source

pub fn reserve(&mut self, additional: usize)

Extend the capacity of the known headers map by this many

source

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

Return an iterator over borrowed header names and header values. First yields the known headers and then the unknown headers, if any.

source

pub fn is_empty(&self) -> bool

Are there zero headers?

source

pub fn len(&self) -> usize

How many unique HeaderName have been added to these Headers? Note that each header name may have more than one HeaderValue.

source

pub fn append( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues>, )

add the header value or header values into this header map. If there is already a header with the same name, the new values will be added to the existing ones. To replace any existing values, use Headers::insert

source

pub fn append_all(&mut self, other: Headers)

A slightly more efficient way to combine two Headers than using Extend

source

pub fn insert_all(&mut self, other: Headers)

Combine two Headers, replacing any existing header values

source

pub fn insert( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues>, )

Add a header value or header values into this header map. If a header already exists with the same name, it will be replaced. To combine, see Headers::append

source

pub fn try_insert( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues>, )

Add a header value or header values into this header map if and only if there is not already a header with the same name.

source

pub fn get_str<'a>(&self, name: impl Into<HeaderName<'a>>) -> Option<&str>

Retrieves a &str header value if there is at least one header in the map with this name. If there are several headers with the same name, this follows the behavior defined at HeaderValues::one. Returns None if there is no header with the provided header name.

source

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

Retrieves a singular header value from this header map. If there are several headers with the same name, this follows the behavior defined at HeaderValues::one. Returns None if there is no header with the provided header name

source

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

Takes all headers with the provided header name out of this header map and returns them. Returns None if the header did not have an entry in this map.

source

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

Retrieves a reference to all header values with the provided header name. If you expect there to be only one value, use Headers::get.

source

pub fn has_header<'a>(&self, name: impl Into<HeaderName<'a>>) -> bool

Predicate function to check whether this header map contains the provided header name. If you are using this to conditionally insert a value, consider using Headers::try_insert instead.

source

pub fn eq_ignore_ascii_case<'a>( &'a self, name: impl Into<HeaderName<'a>>, needle: &str, ) -> bool

Convenience function to check whether the value contained in this header map for the provided name is ascii-case-insensitively equal to the provided comparison &str. Returns false if there is no value for the name

source

pub fn contains_ignore_ascii_case<'a>( &self, name: impl Into<HeaderName<'a>>, needle: &str, ) -> bool

👎Deprecated: Please open an issue if this behavior is important to you. See documentation for deprecation rationale

Deprecated because is likely not what you want. It is rarely the case that headers should be searched for a matching string instead of carefully parsed according to the appropriate header rule. Naive string matching on headers without regard to header structure is a possible source of spec noncompliance or occasionally security vulnerability, so trillium does not go out of its way to facilitate that.

source

pub fn with_inserted_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> Self

Chainable method to insert a header

source

pub fn with_appended_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> Self

Chainable method to append a header

source

pub fn without_header(self, name: impl Into<HeaderName<'static>>) -> Self

Chainable method to remove a header

source

pub fn without_headers<I, H>(self, names: I) -> Self
where I: IntoIterator<Item = H>, H: Into<HeaderName<'static>>,

Chainable method to remove multiple headers by name

source

pub fn remove_all<I, H>(&mut self, names: I)
where I: IntoIterator<Item = H>, H: Into<HeaderName<'static>>,

remove multiple headers by name

source

pub fn try_insert_with<F, V>( &mut self, name: impl Into<HeaderName<'static>>, values_fn: F, )
where F: Fn() -> V, V: Into<HeaderValues>,

if a key does not exist already, execute the provided function and insert a value

this can be useful to avoid calculating an unnecessary header value, or checking for the presence of a key before insertion

Trait Implementations§

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 Default for Headers

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for Headers

source§

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

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

impl<HN, HV> Extend<(HN, HV)> for Headers
where HN: Into<HeaderName<'static>>, HV: Into<HeaderValues>,

source§

fn extend<T: IntoIterator<Item = (HN, HV)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<HN, HV> FromIterator<(HN, HV)> for Headers
where HN: Into<HeaderName<'static>>, HV: Into<HeaderValues>,

source§

fn from_iter<T: IntoIterator<Item = (HN, HV)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a Headers

§

type Item = (HeaderName<'a>, &'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 IntoIterator for Headers

§

type Item = (HeaderName<'static>, HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = IntoIter

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 PartialEq for Headers

source§

fn eq(&self, other: &Headers) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Headers

source§

impl StructuralPartialEq for Headers

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.