fix(client): fix panic when request body is empty string
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user