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:
committed by
Sean McArthur
parent
29a8074689
commit
9a28268b98
@@ -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) => {
|
||||
|
||||
@@ -3,6 +3,7 @@ use h2::Reason;
|
||||
use h2::server::{Builder, Connection, Handshake, SendResponse};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use ::headers::content_length_parse_all;
|
||||
use ::body::Payload;
|
||||
use ::common::Exec;
|
||||
use ::headers;
|
||||
@@ -126,7 +127,10 @@ where
|
||||
{
|
||||
while let Some((req, respond)) = try_ready!(self.conn.poll().map_err(::Error::new_h2)) {
|
||||
trace!("incoming request");
|
||||
let req = req.map(::Body::h2);
|
||||
let content_length = content_length_parse_all(req.headers());
|
||||
let req = req.map(|stream| {
|
||||
::Body::h2(stream, content_length)
|
||||
});
|
||||
let fut = H2Stream::new(service.call(req), respond);
|
||||
exec.execute(fut);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user