pub struct Response<'h, 'b: 'h, const N: usize = MAX_ALLOW_HEADERS> {
    pub sec_accept: &'b [u8],
    pub other_headers: &'h mut [HttpHeader<'b>],
}
Expand description

Http response presentation.

Fields§

§sec_accept: &'b [u8]§other_headers: &'h mut [HttpHeader<'b>]

Implementations§

source§

impl<'h, 'b: 'h> Response<'h, 'b>

source

pub const fn new(sec_accept: &'b [u8]) -> Self

Create a new response without extra headers. This is usually used to send a response.

source

pub const fn new_with_headers( sec_accept: &'b [u8], other_headers: &'h mut [HttpHeader<'b>] ) -> Self

Create a new response with extra headers. This is usually used to send a response.

source

pub const fn new_storage(other_headers: &'h mut [HttpHeader<'b>]) -> Self

Create with user provided headers storage, other fields are left empty. This is usually used to receive a response.

The max decode header size is MAX_ALLOW_HEADERS.

source§

impl<'h, 'b: 'h, const N: usize> Response<'h, 'b, N>

source

pub const fn new_custom_storage(other_headers: &'h mut [HttpHeader<'b>]) -> Self

Create with user provided headers storage, other fields are left empty. This is usually used to receive a response.

The const generic paramater represents the max decode header size.

source

pub fn encode(&self, buf: &mut [u8]) -> Result<usize, HandshakeError>

Encode to a provided buffer, return the number of written bytes.

Necessary headers, including upgrade, connection, and sec-websocket-accept are written to the buffer, then other headers(if any) are written in order.

Caller should make sure there is enough space to write, otherwise a HandshakeError::NotEnoughCapacity error will be returned.

source

pub fn decode(&mut self, buf: &'b [u8]) -> Result<usize, HandshakeError>

Parse from a provided buffer, save the results, and return the number of bytes parsed.

Necessary headers, including upgrade, connection, and sec-websocket-version are parsed and checked, and stored in the struct. Optional headers (like sec-websocket-protocol) are stored in other headers. After the parse, other_headers will be shrunk to fit the number of stored headers.

Caller should make sure there is enough space (default is MAX_ALLOW_HEADERS) to store headers, which could be specified by the const generic paramater. If the buffer does not contain a complete http request, a HandshakeError::NotEnoughData error will be returned. If the required headers(mentioned above) do not pass the check (case insensitive), other corresponding errors will be returned.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'h, 'b, const N: usize = MAX_ALLOW_HEADERS> !UnwindSafe for Response<'h, '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> Same for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V