Skip to content

Commit

Permalink
fix(http): fix returning EarlyEof if supplied buffer is zero-len
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Feb 27, 2017
1 parent e2b1a1a commit 1e740fb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/http/h1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ impl<R> fmt::Debug for HttpReader<R> {

impl<R: Read> Read for HttpReader<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if buf.is_empty() {
return Ok(0);
}
match *self {
SizedReader(ref mut body, ref mut remaining) => {
trace!("Sized read, remaining={:?}", remaining);
Expand Down Expand Up @@ -1076,6 +1079,25 @@ mod tests {
assert_eq!(e.description(), "early eof");
}

#[test]
fn test_read_sized_zero_len_buf() {
let mut r = super::HttpReader::SizedReader(MockStream::with_input(b"foo bar"), 7);
let mut buf = [0u8; 0];
assert_eq!(r.read(&mut buf).unwrap(), 0);
}

#[test]
fn test_read_chunked_zero_len_buf() {
let mut r = super::HttpReader::ChunkedReader(MockStream::with_input(b"\
7\r\n\
foo bar\
0\r\n\r\n\
"), None);

let mut buf = [0u8; 0];
assert_eq!(r.read(&mut buf).unwrap(), 0);
}

#[test]
fn test_message_get_incoming_invalid_content_length() {
let raw = MockStream::with_input(
Expand Down

0 comments on commit 1e740fb

Please sign in to comment.