fix(http1): return error if user body ends prematurely

- update proto::h1::end_body to return Result<()>
- update Encoder::end to return Error(NotEof) only when there's Content-length left to be addressed

Closes #2263
This commit is contained in:
João Oliveira
2020-08-12 22:12:48 +01:00
committed by GitHub
parent 3de81c822e
commit 1ecbcbb119
3 changed files with 15 additions and 8 deletions

View File

@@ -87,7 +87,8 @@ impl Encoder {
Kind::Chunked => Ok(Some(EncodedBuf {
kind: BufKind::ChunkedEnd(b"0\r\n\r\n"),
})),
_ => Err(NotEof),
Kind::CloseDelimited => Ok(None),
Kind::Length(_) => Err(NotEof),
}
}
@@ -405,7 +406,7 @@ mod tests {
assert_eq!(dst, b"foo bar");
assert!(!encoder.is_eof());
encoder.end::<()>().unwrap_err();
encoder.end::<()>().unwrap();
let msg2 = b"baz".as_ref();
let buf2 = encoder.encode(msg2);
@@ -413,6 +414,6 @@ mod tests {
assert_eq!(dst, b"foo barbaz");
assert!(!encoder.is_eof());
encoder.end::<()>().unwrap_err();
encoder.end::<()>().unwrap();
}
}