Response: Use ErrorKind::UnexpectedEof for "premature close"

This commit is contained in:
Ulrik
2021-01-04 15:05:56 +01:00
parent f0245aad23
commit 0ee024f8c2

View File

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