Skip to content

Commit

Permalink
Fix for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jul 28, 2024
1 parent 640a4f2 commit e846ff7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion edge-http/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Error<E> {
IncompleteBody,
InvalidState,
Timeout,
ConnectionClosed,
WsUpgradeError(UpgradeError),
Io(E),
}
Expand Down Expand Up @@ -78,6 +79,7 @@ where
Self::InvalidState => write!(f, "Connection is not in requested state"),
Self::Timeout => write!(f, "Timeout"),
Self::WsUpgradeError(e) => write!(f, "WebSocket upgrade error: {e}"),
Self::ConnectionClosed => write!(f, "Connection closed"),
Self::Io(e) => write!(f, "{e}"),
}
}
Expand Down Expand Up @@ -970,6 +972,13 @@ where

while buf.len() > size {
let read = input.read(&mut buf[offset..]).await.map_err(Error::Io)?;
if read == 0 {
Err(if offset == 0 {
Error::ConnectionClosed
} else {
Error::IncompleteHeaders
})?;
}

offset += read;
size += read;
Expand Down Expand Up @@ -1006,7 +1015,11 @@ where
let read = input.read(&mut byte).await.map_err(Error::Io)?;

if read == 0 {
Err(Error::IncompleteHeaders)?;
Err(if offset == 0 {
Error::ConnectionClosed
} else {
Error::IncompleteHeaders
})?;
}

buf[offset] = byte[0];
Expand Down
4 changes: 4 additions & 0 deletions edge-http/src/io/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ pub async fn handle_task_connection<const N: usize, T, H>(
info!("Handler task {task_id}: Connection closed due to timeout");
break;
}
Err(HandleRequestError::Connection(Error::ConnectionClosed)) => {
debug!("Handler task {task_id}: Connection closed");
break;
}
Err(e) => {
warn!("Handler task {task_id}: Error when handling request: {e:?}");
break;
Expand Down

0 comments on commit e846ff7

Please sign in to comment.