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>
impl<'h, 'b: 'h> Response<'h, 'b>
sourcepub const fn new(sec_accept: &'b [u8]) -> Self
pub const fn new(sec_accept: &'b [u8]) -> Self
Create a new response without extra headers. This is usually used to send a response.
sourcepub const fn new_with_headers(
sec_accept: &'b [u8],
other_headers: &'h mut [HttpHeader<'b>]
) -> Self
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.
sourcepub const fn new_storage(other_headers: &'h mut [HttpHeader<'b>]) -> Self
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>
impl<'h, 'b: 'h, const N: usize> Response<'h, 'b, N>
sourcepub const fn new_custom_storage(other_headers: &'h mut [HttpHeader<'b>]) -> Self
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.
sourcepub fn encode(&self, buf: &mut [u8]) -> Result<usize, HandshakeError>
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.
sourcepub fn decode(&mut self, buf: &'b [u8]) -> Result<usize, HandshakeError>
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.