fix(http): skip zero length chunks when encoding

This commit is contained in:
Sean McArthur
2017-07-17 10:41:36 -07:00
parent 85c6bec98b
commit d6da3f7b40
2 changed files with 5 additions and 1 deletions

View File

@@ -269,6 +269,10 @@ where I: AsyncRead + AsyncWrite,
return Ok(AsyncSink::NotReady(chunk)); return Ok(AsyncSink::NotReady(chunk));
} }
if let Some(chunk) = chunk { if let Some(chunk) = chunk {
if chunk.as_ref().is_empty() {
return Ok(AsyncSink::Ready);
}
let mut cursor = Cursor::new(chunk); let mut cursor = Cursor::new(chunk);
match encoder.encode(&mut self.io, cursor.buf()) { match encoder.encode(&mut self.io, cursor.buf()) {
Ok(n) => { Ok(n) => {

View File

@@ -63,7 +63,7 @@ impl Encoder {
}; };
if n == 0 { if n == 0 {
return Err(io::Error::new(io::ErrorKind::WouldBlock, "would block")); return Err(io::Error::new(io::ErrorKind::WriteZero, "write zero"));
} }
*remaining -= n as u64; *remaining -= n as u64;