diff --git a/src/proto/dispatch.rs b/src/proto/dispatch.rs index 026f855c13..88b16dd003 100644 --- a/src/proto/dispatch.rs +++ b/src/proto/dispatch.rs @@ -202,7 +202,15 @@ where return Ok(Async::NotReady); } }; - assert!(self.conn.write_body(Some(chunk))?.is_ready()); + + if self.conn.can_write_body() { + assert!(self.conn.write_body(Some(chunk))?.is_ready()); + // This allows when chunk is `None`, or `Some([])`. + } else if chunk.as_ref().len() == 0 { + // ok + } else { + warn!("unexpected chunk when body cannot write"); + } } else { return Ok(Async::NotReady); } diff --git a/tests/client.rs b/tests/client.rs index 16b7ab00f0..e600757903 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -65,6 +65,7 @@ macro_rules! test { let res = test! { INNER; + name: $name, core: &mut core, server: expected: $server_expected, @@ -115,6 +116,7 @@ macro_rules! test { let err = test! { INNER; + name: $name, core: &mut core, server: expected: $server_expected, @@ -135,6 +137,7 @@ macro_rules! test { ( INNER; + name: $name:ident, core: $core:expr, server: expected: $server_expected:expr, @@ -299,6 +302,33 @@ test! { body: None, } +test! { + name: client_post_empty, + + server: + expected: "\ + POST /empty HTTP/1.1\r\n\ + Host: {addr}\r\n\ + Content-Length: 0\r\n\ + \r\n\ + ", + reply: REPLY_OK, + + client: + request: + method: Post, + url: "http://{addr}/empty", + headers: [ + ContentLength(0), + ], + body: Some(""), + proxy: false, + response: + status: Ok, + headers: [], + body: None, +} + test! { name: client_http_proxy,