Skip to main content

Headers

Struct Headers 

Source
pub struct Headers { /* private fields */ }
Expand description

Case-insensitive HTTP header container.

Debug formatting redacts values for header names recognised as sensitive (see crate::redact::SENSITIVE_HEADERS) so that logging, error formatting, and panic messages do not leak credentials. Ordinary iteration (iter, get, get_all, keys) is intentionally not redacted — diagnostics are the only output channel that needs to be safe by default.

Implementations§

Source§

impl Headers

Source

pub fn new() -> Self

Create an empty header container.

Source

pub fn insert(&mut self, name: &str, value: &str) -> Result<()>

Insert a header, replacing any existing value with the same name.

§Errors

Returns an error if the name or value is not valid.

Source

pub fn append(&mut self, name: &str, value: &str) -> Result<()>

Append a header value, allowing multiple values for the same name.

§Errors

Returns an error if the name or value is not valid.

Source

pub fn get(&self, name: &str) -> Option<&HeaderValue>

Get a header value by name.

Source

pub fn get_all(&self, name: &str) -> Vec<&HeaderValue>

Get all values for a header by name.

Source

pub fn get_str(&self, name: &str) -> Option<Result<&str, ToStrError>>

Get a header value as a string by name.

Source

pub fn contains(&self, name: &str) -> bool

Returns true if the headers contain a value for the given name.

Source

pub fn len(&self) -> usize

Returns the number of headers.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no headers.

Source

pub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>

Iterate over all header name-value pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &HeaderName>

Iterate over all header names.

Source

pub fn extend(&mut self, other: &Self)

Extend these headers by appending all values from another set.

This is append-only: existing values for a name are preserved and values from other are appended, potentially creating duplicates (e.g. two Content-Type values). This preserves multi-value headers like Set-Cookie. Callers that need replacement semantics should remove the header name first, as the request pipeline does when applying request headers over client defaults, or use Self::extend_replacing.

Source

pub fn extend_replacing(&mut self, other: &Self)

Extend by replacing values for names present in other.

For each header name in other, any existing values in self are removed before appending the values from other. Multi-value headers from other (e.g. Set-Cookie) are preserved.

Source

pub fn remove(&mut self, name: &str) -> Option<HeaderValue>

Remove a header by name (case-insensitive).

Source

pub fn into_inner(self) -> HeaderMap

Consume and return the inner HeaderMap.

Trait Implementations§

Source§

impl Clone for Headers

Source§

fn clone(&self) -> Headers

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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() -> Headers

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

impl From<HeaderMap> for Headers

Source§

fn from(inner: HeaderMap) -> Self

Converts to this type from the input type.

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

Source§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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