morpheus_network::http::headers

Struct Headers

Source
pub struct Headers {
    headers: Vec<Header>,
}
Expand description

Collection of HTTP headers.

Headers are stored in insertion order and support case-insensitive lookup. Multiple headers with the same name are allowed (e.g., Set-Cookie).

Fields§

§headers: Vec<Header>

Implementations§

Source§

impl Headers

Source

pub fn new() -> Self

Create an empty header collection.

Source

pub fn len(&self) -> usize

Number of headers.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn add(&mut self, name: impl Into<String>, value: impl Into<String>)

Add a header (allows duplicates).

Use this when multiple values for the same header are valid (e.g., Set-Cookie).

Source

pub fn set(&mut self, name: impl Into<String>, value: impl Into<String>)

Set a header (replaces existing with same name).

Use this for headers that should have only one value (e.g., Content-Type, Host).

Source

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

Get the first header value by name (case-insensitive).

Source

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

Get all header values by name (case-insensitive).

Source

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

Check if a header exists (case-insensitive).

Source

pub fn remove(&mut self, name: &str) -> usize

Remove all headers with the given name (case-insensitive).

Returns the number of headers removed.

Source

pub fn iter(&self) -> impl Iterator<Item = &Header>

Iterate over all headers.

Source

pub fn clear(&mut self)

Clear all headers.

Source

pub fn content_length(&self) -> Option<usize>

Get Content-Length header as usize.

Source

pub fn set_content_length(&mut self, length: usize)

Set Content-Length header.

Source

pub fn content_type(&self) -> Option<&str>

Get Content-Type header.

Source

pub fn set_content_type(&mut self, content_type: impl Into<String>)

Set Content-Type header.

Source

pub fn is_chunked(&self) -> bool

Check if Transfer-Encoding is chunked.

Source

pub fn host(&self) -> Option<&str>

Get Host header.

Source

pub fn set_host(&mut self, host: impl Into<String>)

Set Host header.

Source

pub fn connection(&self) -> Option<&str>

Get Connection header.

Source

pub fn keep_alive(&self) -> bool

Check if connection should be kept alive.

Source

pub fn to_wire_format(&self) -> String

Serialize headers to wire format (for HTTP requests).

Each header is formatted as: Name: Value\r\n

Source

pub fn from_wire_format(data: &str) -> (Self, usize)

Parse headers from wire format.

Expects format: Name: Value\r\n for each header. Stops at empty line (double CRLF).

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() -> Headers

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

impl PartialEq for Headers

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

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

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.