Struct Headers
pub struct Headers { /* private fields */ }Expand description
Trillium’s header map type
Implementations§
§impl Headers
impl Headers
pub fn iter(&self) -> Iter<'_> ⓘ
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.
pub fn len(&self) -> usize
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.
pub fn append(
&mut self,
name: impl Into<HeaderName<'static>>,
values: impl Into<HeaderValues>,
) -> &mut HeaderValues
pub fn append( &mut self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> &mut 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
Identical to headers.entry(name).append(values)
pub fn append_all(&mut self, other: Headers)
pub fn append_all(&mut self, other: Headers)
pub fn insert_all(&mut self, other: Headers)
pub fn insert_all(&mut self, other: Headers)
Combine two Headers, replacing any existing header values
pub fn insert(
&mut self,
name: impl Into<HeaderName<'static>>,
values: impl Into<HeaderValues>,
) -> &mut Headers
pub fn insert( &mut self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> &mut Headers
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
pub fn try_insert(
&mut self,
name: impl Into<HeaderName<'static>>,
values: impl Into<HeaderValues>,
) -> &mut Headers
pub fn try_insert( &mut self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> &mut Headers
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.
Identical to headers.entry(name).or_insert(default)
pub fn try_insert_with<V>(
&mut self,
name: impl Into<HeaderName<'static>>,
values: impl FnOnce() -> V,
) -> &mut HeaderValueswhere
V: Into<HeaderValues>,
pub fn try_insert_with<V>(
&mut self,
name: impl Into<HeaderName<'static>>,
values: impl FnOnce() -> V,
) -> &mut HeaderValueswhere
V: Into<HeaderValues>,
if a key does not exist already, execute the provided function and insert a value
Identical to
headers.entry(name).or_insert_with(values)
pub fn entry(&mut self, name: impl Into<HeaderName<'static>>) -> Entry<'_>
pub fn entry(&mut self, name: impl Into<HeaderName<'static>>) -> Entry<'_>
Return a view into the entry for this header name, whether or not it is populated.
See also Entry
pub fn get_str<'a>(&self, name: impl Into<HeaderName<'a>>) -> Option<&str>
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.
pub fn get<'a>(&self, name: impl Into<HeaderName<'a>>) -> Option<&HeaderValue>
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
pub fn remove<'a>(
&mut self,
name: impl Into<HeaderName<'a>>,
) -> Option<HeaderValues>
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.
pub fn get_values<'a>(
&self,
name: impl Into<HeaderName<'a>>,
) -> Option<&HeaderValues>
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.
pub fn has_header<'a>(&self, name: impl Into<HeaderName<'a>>) -> bool
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.
pub fn eq_ignore_ascii_case<'a>(
&'a self,
name: impl Into<HeaderName<'a>>,
needle: &str,
) -> bool
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
pub fn with_inserted_header(
self,
name: impl Into<HeaderName<'static>>,
values: impl Into<HeaderValues>,
) -> Headers
pub fn with_inserted_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> Headers
Chainable method to insert a header
pub fn with_appended_header(
self,
name: impl Into<HeaderName<'static>>,
values: impl Into<HeaderValues>,
) -> Headers
pub fn with_appended_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues>, ) -> Headers
Chainable method to append a header
pub fn without_header<'a>(self, name: impl Into<HeaderName<'a>>) -> Headers
pub fn without_header<'a>(self, name: impl Into<HeaderName<'a>>) -> Headers
Chainable method to remove a header
pub fn without_headers<'a, I, H>(self, names: I) -> Headers
pub fn without_headers<'a, I, H>(self, names: I) -> Headers
Chainable method to remove multiple headers by name
pub fn remove_all<'a, I, H>(&mut self, names: I)
pub fn remove_all<'a, I, H>(&mut self, names: I)
remove multiple headers by name
Trait Implementations§
§impl<HN, HV> Extend<(HN, HV)> for Headers
impl<HN, HV> Extend<(HN, HV)> for Headers
§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (HN, HV)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (HN, HV)>,
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)§impl<HN, HV> FromIterator<(HN, HV)> for Headers
impl<HN, HV> FromIterator<(HN, HV)> for Headers
Source§impl Handler for Headers
impl Handler for Headers
Source§async fn run(&self, conn: Conn) -> Conn
async fn run(&self, conn: Conn) -> Conn
Source§fn init(&mut self, info: &mut Info) -> impl Future<Output = ()> + Send
fn init(&mut self, info: &mut Info) -> impl Future<Output = ()> + Send
Source§fn before_send(&self, conn: Conn) -> impl Future<Output = Conn> + Send
fn before_send(&self, conn: Conn) -> impl Future<Output = Conn> + Send
Source§fn has_upgrade(&self, upgrade: &Upgrade) -> bool
fn has_upgrade(&self, upgrade: &Upgrade) -> bool
Handler::upgrade. The first handler that responds true to this will receive
ownership of the trillium::Upgrade in a subsequent call to
Handler::upgradeSource§fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
Handler::has_upgrade and will
only be called once for this upgrade. There is no return value, and this function takes
exclusive ownership of the underlying transport once this is called. You can downcast
the transport to whatever the source transport type is and perform any non-http protocol
communication that has been negotiated. You probably don’t want this unless you’re
implementing something like websockets. Please note that for many transports such as
TcpStreams, dropping the transport (and therefore the Upgrade) will hang up /
disconnect.§impl<'a> IntoIterator for &'a Headers
impl<'a> IntoIterator for &'a Headers
§type Item = (HeaderName<'a>, &'a HeaderValues)
type Item = (HeaderName<'a>, &'a HeaderValues)
§impl IntoIterator for Headers
impl IntoIterator for Headers
§type Item = (HeaderName<'static>, HeaderValues)
type Item = (HeaderName<'static>, HeaderValues)
impl Eq for Headers
impl StructuralPartialEq for 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 UnsafeUnpin 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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.