pub struct Request<'h, 'b: 'h, const N: usize = MAX_ALLOW_HEADERS> {
pub path: &'b [u8],
pub host: &'b [u8],
pub sec_key: &'b [u8],
pub other_headers: &'h mut [HttpHeader<'b>],
}
Expand description
Http request presentation.
Fields§
§path: &'b [u8]
§host: &'b [u8]
§sec_key: &'b [u8]
§other_headers: &'h mut [HttpHeader<'b>]
Implementations§
source§impl<'h, 'b: 'h> Request<'h, 'b>
impl<'h, 'b: 'h> Request<'h, 'b>
sourcepub const fn new(path: &'b [u8], host: &'b [u8], sec_key: &'b [u8]) -> Self
pub const fn new(path: &'b [u8], host: &'b [u8], sec_key: &'b [u8]) -> Self
Create a new request without extra headers. This is usually used to send a request.
sourcepub const fn new_with_headers(
path: &'b [u8],
host: &'b [u8],
sec_key: &'b [u8],
other_headers: &'h mut [HttpHeader<'b>]
) -> Self
pub const fn new_with_headers( path: &'b [u8], host: &'b [u8], sec_key: &'b [u8], other_headers: &'h mut [HttpHeader<'b>] ) -> Self
Create a new request with extra headers. This is usually used to send a request.
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 request.
The max decode header size is MAX_ALLOW_HEADERS
.
source§impl<'h, 'b: 'h, const N: usize> Request<'h, 'b, N>
impl<'h, 'b: 'h, const N: usize> Request<'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 request.
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 host
, upgrade
, connection
,
sec-websocket-key
and sec-websocket-version
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 host
, upgrade
, connection
,
sec-websocket-key
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.