Skip to content

Commit

Permalink
fix(client): fix panic when request body is empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Dec 26, 2017
1 parent 11bf254 commit bfb0f84
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/proto/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ macro_rules! test {

let res = test! {
INNER;
name: $name,
core: &mut core,
server:
expected: $server_expected,
Expand Down Expand Up @@ -115,6 +116,7 @@ macro_rules! test {

let err = test! {
INNER;
name: $name,
core: &mut core,
server:
expected: $server_expected,
Expand All @@ -135,6 +137,7 @@ macro_rules! test {

(
INNER;
name: $name:ident,
core: $core:expr,
server:
expected: $server_expected:expr,
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit bfb0f84

Please sign in to comment.