feat(http2): Add content_length() value to incoming h2 Body

- Add `Body::Kind::H2` to contain the content length of the body.
- Update `Body::content_length` to return the content length if `Body::Kind` is `H2`, instead of returning `None`.

Reference: #1556, #1557

Closes #1546
This commit is contained in:
Josh Leeb-du Toit
2018-06-19 04:50:12 +10:00
committed by Sean McArthur
parent 29a8074689
commit 9a28268b98
4 changed files with 58 additions and 49 deletions

View File

@@ -5,6 +5,7 @@ use futures::sync::mpsc;
use h2::client::{Builder, Handshake, SendRequest};
use tokio_io::{AsyncRead, AsyncWrite};
use headers::content_length_parse_all;
use body::Payload;
use ::common::{Exec, Never};
use headers;
@@ -135,7 +136,9 @@ where
.then(move |result| {
match result {
Ok(res) => {
let res = res.map(::Body::h2);
let content_length = content_length_parse_all(res.headers());
let res = res.map(|stream|
::Body::h2(stream, content_length));
let _ = cb.send(Ok(res));
},
Err(err) => {