Skip to content

Commit

Permalink
refactor req.clear aand its position
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarus committed Aug 21, 2024
1 parent 14756d9 commit 894d467
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions ohkami/src/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ impl Request {
#[cfg(any(feature="rt_tokio",feature="rt_async-std"))]
#[inline]
pub(crate) fn clear(&mut self) {
for b in &mut *self.__buf__ {
match b {0 => break, _ => *b = 0}
}
self.path = Path::uninit();
self.query = None;
self.headers.clear();
self.payload = None;
self.store.clear();
if self.__buf__[0] != 0 {
for b in &mut *self.__buf__ {
match b {0 => break, _ => *b = 0}
}
self.path = Path::uninit();
self.query = None;
self.headers.clear();
self.payload = None;
self.store.clear();
} /* else: just after `init`ed or `clear`ed */
}

#[cfg(any(feature="rt_tokio",feature="rt_async-std"))]
Expand Down
2 changes: 1 addition & 1 deletion ohkami/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl Session {
let mut req = Request::init();
let mut req = unsafe {Pin::new_unchecked(&mut req)};
loop {
req.clear();
match req.as_mut().read(&mut self.connection).await {
Ok(Some(())) => {
let close = matches!(req.headers.Connection(), Some("close" | "Close"));
Expand All @@ -86,7 +87,6 @@ impl Session {
Ok(None) => break Upgrade::None,
Err(res) => {res.send(&mut self.connection).await;},
}
req.clear()
}
}).await {
Some(Upgrade::None) | None => {
Expand Down

0 comments on commit 894d467

Please sign in to comment.