feat(body): make Body know about incoming Content-Length

When getting a `Body` from hyper, such as in a client response,
the method `Body::content_length()` now returns a value if the header
was present.

Closes #1545
This commit is contained in:
Laurențiu Nicola
2018-06-08 22:00:46 +02:00
committed by Sean McArthur
parent 396fe80e76
commit a0a0fcdd9b
5 changed files with 108 additions and 20 deletions

View File

@@ -190,9 +190,14 @@ where
}
// dispatch is ready for a message, try to read one
match self.conn.read_head() {
Ok(Async::Ready(Some((head, has_body)))) => {
let body = if has_body {
let (mut tx, rx) = Body::channel();
Ok(Async::Ready(Some((head, body_len)))) => {
let body = if let Some(body_len) = body_len {
let (mut tx, rx) =
Body::new_channel(if let BodyLength::Known(len) = body_len {
Some(len)
} else {
None
});
let _ = tx.poll_ready(); // register this task if rx is dropped
self.body_tx = Some(tx);
rx
@@ -201,7 +206,7 @@ where
};
self.dispatch.recv_msg(Ok((head, body)))?;
Ok(Async::Ready(()))
},
}
Ok(Async::Ready(None)) => {
// read eof, conn will start to shutdown automatically
Ok(Async::Ready(()))