Response: Use ErrorKind::UnexpectedEof for "premature close" (#293)

In a client application, we're explicitly trying to differentiate "invalid data"
scenarios from "broken transfer".
This commit is contained in:
Jacob Hoffman-Andrews
2021-01-10 13:25:42 -08:00
committed by GitHub

View File

@@ -583,7 +583,7 @@ impl<R: Read> Read for LimitedRead<R> {
// received, the recipient MUST consider the message to be
// incomplete and close the connection.
Ok(0) => Err(io::Error::new(
io::ErrorKind::InvalidData,
io::ErrorKind::UnexpectedEof,
"response body closed before all bytes were read",
)),
Ok(amount) => {
@@ -601,7 +601,7 @@ fn short_read() {
let mut lr = LimitedRead::new(Cursor::new(vec![b'a'; 3]), 10);
let mut buf = vec![0; 1000];
let result = lr.read_to_end(&mut buf);
assert!(result.is_err());
assert!(result.err().unwrap().kind() == io::ErrorKind::UnexpectedEof);
}
impl<R: Read> From<LimitedRead<R>> for Stream