Skip to content

Commit

Permalink
fix(http): allow zero-length chunks when no body is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 18, 2017
1 parent 89f7803 commit 9b47e18
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/http/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 9b47e18

Please sign in to comment.