Skip to content

Commit e846ff7

Browse files
committed
Fix for #20
1 parent 640a4f2 commit e846ff7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

edge-http/src/io.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum Error<E> {
2626
IncompleteBody,
2727
InvalidState,
2828
Timeout,
29+
ConnectionClosed,
2930
WsUpgradeError(UpgradeError),
3031
Io(E),
3132
}
@@ -78,6 +79,7 @@ where
7879
Self::InvalidState => write!(f, "Connection is not in requested state"),
7980
Self::Timeout => write!(f, "Timeout"),
8081
Self::WsUpgradeError(e) => write!(f, "WebSocket upgrade error: {e}"),
82+
Self::ConnectionClosed => write!(f, "Connection closed"),
8183
Self::Io(e) => write!(f, "{e}"),
8284
}
8385
}
@@ -970,6 +972,13 @@ where
970972

971973
while buf.len() > size {
972974
let read = input.read(&mut buf[offset..]).await.map_err(Error::Io)?;
975+
if read == 0 {
976+
Err(if offset == 0 {
977+
Error::ConnectionClosed
978+
} else {
979+
Error::IncompleteHeaders
980+
})?;
981+
}
973982

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

10081017
if read == 0 {
1009-
Err(Error::IncompleteHeaders)?;
1018+
Err(if offset == 0 {
1019+
Error::ConnectionClosed
1020+
} else {
1021+
Error::IncompleteHeaders
1022+
})?;
10101023
}
10111024

10121025
buf[offset] = byte[0];

edge-http/src/io/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ pub async fn handle_task_connection<const N: usize, T, H>(
419419
info!("Handler task {task_id}: Connection closed due to timeout");
420420
break;
421421
}
422+
Err(HandleRequestError::Connection(Error::ConnectionClosed)) => {
423+
debug!("Handler task {task_id}: Connection closed");
424+
break;
425+
}
422426
Err(e) => {
423427
warn!("Handler task {task_id}: Error when handling request: {e:?}");
424428
break;

0 commit comments

Comments
 (0)