Update http body
This commit is contained in:
@@ -57,10 +57,10 @@ where
|
||||
}
|
||||
|
||||
fn call(&mut self, request: Request<B>) -> Self::Future {
|
||||
let (parts, body) = request.into_parts();
|
||||
let (parts, mut body) = request.into_parts();
|
||||
let request = Request::from_parts(parts, ());
|
||||
|
||||
let eos = body.is_end_stream();
|
||||
let eos = Pin::new(&mut body).is_end_stream();
|
||||
|
||||
let res = self.client.send_request(request, eos);
|
||||
|
||||
|
||||
+14
-13
@@ -13,7 +13,7 @@ where
|
||||
S: Body,
|
||||
{
|
||||
h2: SendStream<SendBuf<S::Data>>,
|
||||
body: S,
|
||||
body: Pin<Box<dyn Body<Data = S::Data, Error = S::Error> + Send + 'static>>,
|
||||
state: FlushState,
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ enum DataOrTrailers<B> {
|
||||
|
||||
impl<S> Flush<S>
|
||||
where
|
||||
S: Body,
|
||||
S: Body + Send + 'static,
|
||||
S::Error: Into<Box<dyn std::error::Error>>,
|
||||
{
|
||||
pub fn new(src: S, dst: SendStream<SendBuf<S::Data>>) -> Self {
|
||||
Flush {
|
||||
h2: dst,
|
||||
body: src,
|
||||
body: Box::pin(src),
|
||||
state: FlushState::Data,
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ where
|
||||
loop {
|
||||
match ready!(self.poll_body(cx)) {
|
||||
Some(Ok(Data(buf))) => {
|
||||
let eos = self.body.is_end_stream();
|
||||
let eos = Pin::new(&mut self.body).is_end_stream();
|
||||
|
||||
self.h2.send_data(SendBuf::new(buf), eos)?;
|
||||
|
||||
@@ -125,7 +125,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
let item = match ready!(self.body.poll_data(cx)) {
|
||||
let item = match ready!(Pin::new(&mut self.body).poll_data(cx)) {
|
||||
Some(Ok(d)) => Some(d),
|
||||
Some(Err(err)) => {
|
||||
let err = err.into();
|
||||
@@ -162,13 +162,14 @@ where
|
||||
// before we get a RST_STREAM.
|
||||
}
|
||||
}
|
||||
let trailers = ready!(self.body.poll_trailers(cx).map_err(|err| {
|
||||
let err = err.into();
|
||||
debug!("user body error from poll_trailers: {}", err);
|
||||
let reason = crate::error::reason_from_dyn_error(&*err);
|
||||
self.h2.send_reset(reason);
|
||||
reason
|
||||
}))?;
|
||||
let trailers =
|
||||
ready!(Pin::new(&mut self.body).poll_trailers(cx).map_err(|err| {
|
||||
let err = err.into();
|
||||
debug!("user body error from poll_trailers: {}", err);
|
||||
let reason = crate::error::reason_from_dyn_error(&*err);
|
||||
self.h2.send_reset(reason);
|
||||
reason
|
||||
}))?;
|
||||
self.state = FlushState::Done;
|
||||
if let Some(trailers) = trailers {
|
||||
return Some(Ok(DataOrTrailers::Trailers(trailers))).into();
|
||||
@@ -182,7 +183,7 @@ where
|
||||
|
||||
impl<S> Future for Flush<S>
|
||||
where
|
||||
S: Body + Unpin,
|
||||
S: Body + Send + 'static,
|
||||
S::Error: Into<Box<dyn std::error::Error>>,
|
||||
{
|
||||
type Output = Result<(), ()>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use bytes::{Buf, Bytes, BytesMut};
|
||||
use futures_util::TryStreamExt;
|
||||
use http_body::Body;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
/// Allows a stream to be read from the remote.
|
||||
@@ -33,11 +34,14 @@ impl Body for RecvBody {
|
||||
type Data = Data;
|
||||
type Error = h2::Error;
|
||||
|
||||
fn is_end_stream(&self) -> bool {
|
||||
fn is_end_stream(self: Pin<&mut Self>) -> bool {
|
||||
self.inner.is_end_stream()
|
||||
}
|
||||
|
||||
fn poll_data(&mut self, cx: &mut Context<'_>) -> Poll<Option<Result<Self::Data, h2::Error>>> {
|
||||
fn poll_data(
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Option<Result<Self::Data, h2::Error>>> {
|
||||
let data = match futures_util::ready!(self.inner.try_poll_next_unpin(cx)) {
|
||||
Some(Ok(bytes)) => {
|
||||
self.inner
|
||||
@@ -54,7 +58,7 @@ impl Body for RecvBody {
|
||||
}
|
||||
|
||||
fn poll_trailers(
|
||||
&mut self,
|
||||
mut self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<Option<http::HeaderMap>, h2::Error>> {
|
||||
match futures_util::ready!(self.inner.poll_trailers(cx)) {
|
||||
|
||||
@@ -86,10 +86,10 @@ pub async fn handle_request<B>(
|
||||
B::Data: Unpin,
|
||||
B::Error: Into<Box<dyn std::error::Error>>,
|
||||
{
|
||||
let (parts, body) = response.into_parts();
|
||||
let (parts, mut body) = response.into_parts();
|
||||
|
||||
// Check if the response is imemdiately an end-of-stream.
|
||||
let eos = body.is_end_stream();
|
||||
let eos = std::pin::Pin::new(&mut body).is_end_stream();
|
||||
|
||||
let response = Response::from_parts(parts, ());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user