feat(body): implement http_body::Body for hyper::Body
This adds a `http_body::Body` impl for hypers `Body`. This should allow us to start moving to a more generic body trait based on `BufStream` and `http-body`.
This commit is contained in:
committed by
Sean McArthur
parent
973f981aa5
commit
2d9f3490aa
@@ -22,6 +22,7 @@ bytes = "0.4.4"
|
|||||||
futures = "0.1.21"
|
futures = "0.1.21"
|
||||||
futures-cpupool = { version = "0.1.6", optional = true }
|
futures-cpupool = { version = "0.1.6", optional = true }
|
||||||
http = "0.1.15"
|
http = "0.1.15"
|
||||||
|
http-body = "0.1"
|
||||||
httparse = "1.0"
|
httparse = "1.0"
|
||||||
h2 = "0.1.10"
|
h2 = "0.1.10"
|
||||||
iovec = "0.1"
|
iovec = "0.1"
|
||||||
@@ -30,6 +31,7 @@ log = "0.4"
|
|||||||
net2 = { version = "0.2.32", optional = true }
|
net2 = { version = "0.2.32", optional = true }
|
||||||
time = "0.1"
|
time = "0.1"
|
||||||
tokio = { version = "0.1.14", optional = true, default-features = false, features = ["rt-full"] }
|
tokio = { version = "0.1.14", optional = true, default-features = false, features = ["rt-full"] }
|
||||||
|
tokio-buf = "0.1"
|
||||||
tokio-executor = { version = "0.1.0", optional = true }
|
tokio-executor = { version = "0.1.0", optional = true }
|
||||||
tokio-io = "0.1"
|
tokio-io = "0.1"
|
||||||
tokio-reactor = { version = "0.1", optional = true }
|
tokio-reactor = { version = "0.1", optional = true }
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::fmt;
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::sync::{mpsc, oneshot};
|
use futures::sync::{mpsc, oneshot};
|
||||||
use futures::{Async, Future, Poll, Stream, Sink, AsyncSink, StartSend};
|
use futures::{Async, Future, Poll, Stream, Sink, AsyncSink, StartSend};
|
||||||
|
use tokio_buf::SizeHint;
|
||||||
use h2;
|
use h2;
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
|
|
||||||
@@ -332,6 +333,36 @@ impl Payload for Body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ::http_body::Body for Body {
|
||||||
|
type Data = Chunk;
|
||||||
|
type Error = ::Error;
|
||||||
|
|
||||||
|
fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error> {
|
||||||
|
<Self as Payload>::poll_data(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_trailers(&mut self) -> Poll<Option<HeaderMap>, Self::Error> {
|
||||||
|
<Self as Payload>::poll_trailers(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_end_stream(&self) -> bool {
|
||||||
|
<Self as Payload>::is_end_stream(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> SizeHint {
|
||||||
|
let mut hint = SizeHint::default();
|
||||||
|
|
||||||
|
let content_length = <Self as Payload>::content_length(self);
|
||||||
|
|
||||||
|
if let Some(size) = content_length {
|
||||||
|
hint.set_upper(size);
|
||||||
|
hint.set_lower(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
hint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Stream for Body {
|
impl Stream for Body {
|
||||||
type Item = Chunk;
|
type Item = Chunk;
|
||||||
type Error = ::Error;
|
type Error = ::Error;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ extern crate bytes;
|
|||||||
#[cfg(feature = "runtime")] extern crate futures_cpupool;
|
#[cfg(feature = "runtime")] extern crate futures_cpupool;
|
||||||
extern crate h2;
|
extern crate h2;
|
||||||
#[doc(hidden)] pub extern crate http;
|
#[doc(hidden)] pub extern crate http;
|
||||||
|
extern crate http_body;
|
||||||
extern crate httparse;
|
extern crate httparse;
|
||||||
extern crate iovec;
|
extern crate iovec;
|
||||||
extern crate itoa;
|
extern crate itoa;
|
||||||
@@ -29,6 +30,7 @@ extern crate itoa;
|
|||||||
#[cfg(feature = "runtime")] extern crate net2;
|
#[cfg(feature = "runtime")] extern crate net2;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
#[cfg(feature = "runtime")] extern crate tokio;
|
#[cfg(feature = "runtime")] extern crate tokio;
|
||||||
|
extern crate tokio_buf;
|
||||||
#[cfg(feature = "runtime")] extern crate tokio_executor;
|
#[cfg(feature = "runtime")] extern crate tokio_executor;
|
||||||
#[macro_use] extern crate tokio_io;
|
#[macro_use] extern crate tokio_io;
|
||||||
#[cfg(feature = "runtime")] extern crate tokio_reactor;
|
#[cfg(feature = "runtime")] extern crate tokio_reactor;
|
||||||
|
|||||||
Reference in New Issue
Block a user