Skip to content

Commit

Permalink
Restore the const constructor new() and call it in the library
Browse files Browse the repository at this point in the history
  • Loading branch information
showier-drastic committed Oct 11, 2024
1 parent 89d692b commit 5ed9f67
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion edge-http/src/io/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ where

let mut state = self.unbind();
let buf_ptr: *mut [u8] = state.buf;
let mut response = ResponseHeaders::default();
let mut response = ResponseHeaders::new();

match response
.receive(state.buf, &mut state.io.as_mut().unwrap(), true)
Expand Down
2 changes: 1 addition & 1 deletion edge-http/src/io/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
buf: &'b mut [u8],
mut io: T,
) -> Result<Connection<'b, T, N>, Error<T::Error>> {
let mut request = RequestHeaders::default();
let mut request = RequestHeaders::new();

let (buf, read_len) = request.receive(buf, &mut io, true).await?;

Expand Down
36 changes: 24 additions & 12 deletions edge-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ pub struct RequestHeaders<'b, const N: usize> {
}

impl<const N: usize> RequestHeaders<'_, N> {
// Create a new RequestHeaders instance, defaults to GET / HTTP/1.1
#[inline(always)]
pub const fn new() -> Self {
Self {
http11: true,
method: Method::Get,
path: "/",
headers: Headers::new(),
}
}

/// A utility method to check if the request is a Websocket upgrade request
pub fn is_ws_upgrade_request(&self) -> bool {
is_upgrade_request(self.method, self.headers.iter())
Expand All @@ -726,12 +737,7 @@ impl<const N: usize> RequestHeaders<'_, N> {
impl<'b, const N: usize> Default for RequestHeaders<'b, N> {
#[inline(always)]
fn default() -> Self {
Self {
http11: true,
method: Method::Get,
path: "/",
headers: Headers::new(),
}
Self::new()
}
}

Expand Down Expand Up @@ -767,6 +773,17 @@ pub struct ResponseHeaders<'b, const N: usize> {
}

impl<const N: usize> ResponseHeaders<'_, N> {
/// Create a new ResponseHeaders instance, defaults to HTTP/1.1 200 OK
#[inline(always)]
pub const fn new() -> Self {
Self {
http11: true,
code: 200,
reason: None,
headers: Headers::new(),
}
}

/// A utility method to check if the response is a Websocket upgrade response
/// and if the upgrade was accepted
pub fn is_ws_upgrade_accepted(
Expand All @@ -781,12 +798,7 @@ impl<const N: usize> ResponseHeaders<'_, N> {
impl<'b, const N: usize> Default for ResponseHeaders<'b, N> {
#[inline(always)]
fn default() -> Self {
Self {
http11: true,
code: 200,
reason: None,
headers: Headers::new(),
}
Self::new()
}
}

Expand Down

0 comments on commit 5ed9f67

Please sign in to comment.