return NeedMoreData when ContentLength and empty chunk

Otherwise, we get stuck in a loop if the buffer is empty
This commit is contained in:
soup 2024-10-14 23:22:48 -04:00
parent 8014ec4076
commit 29a2fd3c7f
No known key found for this signature in database
3 changed files with 21 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

17
Cargo.lock generated Normal file
View file

@ -0,0 +1,17 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "uhttp"
version = "0.1.0"
dependencies = [
"uhttp-ext",
]
[[package]]
name = "uhttp-ext"
version = "0.1.0"
dependencies = [
"uhttp",
]

View file

@ -168,6 +168,9 @@ impl Connection {
(_, StateRecv::Body(body_state)) => match body_state {
BodyState::ContentLength(remaining) => {
if bytes.is_empty() && *remaining != 0 {
return fail(ErrorKind::NeedMoreData).tup(bytes);
}
if bytes.len() < *remaining {
Ok((
&[] as &[u8],