From 9b47e1861a6bd766f21c88b95ecfc9b45fad874d Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 18 Jul 2017 12:01:53 -0700 Subject: [PATCH] fix(http): allow zero-length chunks when no body is allowed --- src/http/conn.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/http/conn.rs b/src/http/conn.rs index c88888620f..b86feb8e80 100644 --- a/src/http/conn.rs +++ b/src/http/conn.rs @@ -441,7 +441,8 @@ where I: AsyncRead + AsyncWrite, }) } }); - } else if chunk.is_none() { + // This allows when chunk is `None`, or `Some([])`. + } else if chunk.as_ref().map(|c| c.as_ref().len()).unwrap_or(0) == 0 { return Ok(AsyncSink::Ready); } else { Frame::Body { chunk: chunk } @@ -932,4 +933,15 @@ mod tests { assert!(conn.state.is_write_closed()); } + + #[test] + fn test_conn_write_empty_chunk() { + let io = AsyncIo::new_buf(vec![], 0); + let mut conn = Conn::<_, http::Chunk, ServerTransaction>::new(io, Default::default()); + conn.state.writing = Writing::KeepAlive; + + assert!(conn.start_send(Frame::Body { chunk: None }).unwrap().is_ready()); + assert!(conn.start_send(Frame::Body { chunk: Some(Vec::new().into()) }).unwrap().is_ready()); + conn.start_send(Frame::Body { chunk: Some(vec![b'a'].into()) }).unwrap_err(); + } }