Update http body
This commit is contained in:
@@ -4,7 +4,7 @@ use futures_util::future;
|
||||
use http::{Request, Response};
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_buf::BufStream;
|
||||
use std::pin::Pin;
|
||||
use tower_h2::{RecvBody, Server};
|
||||
use tower_service::Service;
|
||||
|
||||
@@ -84,11 +84,14 @@ impl From<Vec<u8>> for Body {
|
||||
}
|
||||
}
|
||||
|
||||
impl BufStream for Body {
|
||||
type Item = std::io::Cursor<Vec<u8>>;
|
||||
impl http_body::Body for Body {
|
||||
type Data = std::io::Cursor<Vec<u8>>;
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn poll_buf(&mut self, _cx: &mut Context<'_>) -> Poll<Option<Result<Self::Item, Self::Error>>> {
|
||||
fn poll_data(
|
||||
mut self: Pin<&mut Self>,
|
||||
_cx: &mut Context<'_>,
|
||||
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
|
||||
if self.0.is_empty() {
|
||||
return None.into();
|
||||
}
|
||||
@@ -100,4 +103,11 @@ impl BufStream for Body {
|
||||
|
||||
Some(Ok(buf)).into()
|
||||
}
|
||||
|
||||
fn poll_trailers(
|
||||
self: Pin<&mut Self>,
|
||||
_cx: &mut Context<'_>,
|
||||
) -> Poll<Result<Option<http::HeaderMap>, Self::Error>> {
|
||||
Ok(None).into()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user