Headers

Struct Headers 

Source
pub struct Headers<'b, const N: usize = 64>(/* private fields */);
Expand description

HTTP headers

Implementations§

Source§

impl<'b, const N: usize> Headers<'b, N>

Source

pub const fn new() -> Self

Create a new Headers instance

Source

pub fn content_len(&self) -> Option<u64>

Utility method to return the value of the Content-Length header, if present

Source

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

Utility method to return the value of the Content-Type header, if present

Source

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

Utility method to return the value of the Content-Encoding header, if present

Source

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

Utility method to return the value of the Transfer-Encoding header, if present

Source

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

Utility method to return the value of the Host header, if present

Source

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

Utility method to return the value of the Connection header, if present

Source

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

Utility method to return the value of the Cache-Control header, if present

Source

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

Utility method to return the value of the Upgrade header, if present

Source

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

Iterate over all headers

Source

pub fn iter_raw(&self) -> impl Iterator<Item = (&str, &[u8])>

Iterate over all headers, returning the values as raw byte slices

Source

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

Get the value of a header by name

Source

pub fn get_raw(&self, name: &str) -> Option<&[u8]>

Get the raw value of a header by name, returning the value as a raw byte slice

Source

pub fn set(&mut self, name: &'b str, value: &'b str) -> &mut Self

Set a header by name and value

Source

pub fn set_raw(&mut self, name: &'b str, value: &'b [u8]) -> &mut Self

Set a header by name and value, using a raw byte slice for the value

Source

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

Remove a header by name

Source

pub fn set_content_len( &mut self, content_len: u64, buf: &'b mut String<20>, ) -> &mut Self

A utility method to set the Content-Length header

Source

pub fn set_content_type(&mut self, content_type: &'b str) -> &mut Self

A utility method to set the Content-Type header

Source

pub fn set_content_encoding(&mut self, content_encoding: &'b str) -> &mut Self

A utility method to set the Content-Encoding header

Source

pub fn set_transfer_encoding(&mut self, transfer_encoding: &'b str) -> &mut Self

A utility method to set the Transfer-Encoding header

Source

pub fn set_transfer_encoding_chunked(&mut self) -> &mut Self

A utility method to set the Transfer-Encoding: Chunked header

Source

pub fn set_host(&mut self, host: &'b str) -> &mut Self

A utility method to set the Host header

Source

pub fn set_connection(&mut self, connection: &'b str) -> &mut Self

A utility method to set the Connection header

Source

pub fn set_connection_close(&mut self) -> &mut Self

A utility method to set the Connection: Close header

Source

pub fn set_connection_keep_alive(&mut self) -> &mut Self

A utility method to set the Connection: Keep-Alive header

Source

pub fn set_connection_upgrade(&mut self) -> &mut Self

A utility method to set the Connection: Upgrade header

Source

pub fn set_cache_control(&mut self, cache: &'b str) -> &mut Self

A utility method to set the Cache-Control header

Source

pub fn set_cache_control_no_cache(&mut self) -> &mut Self

A utility method to set the Cache-Control: No-Cache header

Source

pub fn set_upgrade(&mut self, upgrade: &'b str) -> &mut Self

A utility method to set the Upgrade header

Source

pub fn set_upgrade_websocket(&mut self) -> &mut Self

A utility method to set the Upgrade: websocket header

Source

pub fn set_ws_upgrade_request_headers( &mut self, host: Option<&'b str>, origin: Option<&'b str>, version: Option<&'b str>, nonce: &[u8; 16], buf: &'b mut [u8; 28], ) -> &mut Self

A utility method to set all Websocket upgrade request headers, including the Sec-WebSocket-Key header with the base64-encoded nonce

Source

pub fn set_ws_upgrade_response_headers<'a, H>( &mut self, request_headers: H, version: Option<&'a str>, buf: &'b mut [u8; 33], ) -> Result<&mut Self, UpgradeError>
where H: IntoIterator<Item = (&'a str, &'a str)>,

A utility method to set all Websocket upgrade response headers including the Sec-WebSocket-Accept header with the base64-encoded response

Trait Implementations§

Source§

impl<'b, const N: usize> Debug for Headers<'b, N>

Source§

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

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

impl<const N: usize> Default for Headers<'_, N>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'b, const N: usize> Freeze for Headers<'b, N>

§

impl<'b, const N: usize> RefUnwindSafe for Headers<'b, N>

§

impl<'b, const N: usize> Send for Headers<'b, N>

§

impl<'b, const N: usize> Sync for Headers<'b, N>

§

impl<'b, const N: usize> Unpin for Headers<'b, N>

§

impl<'b, const N: usize> UnwindSafe for Headers<'b, N>

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.

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