feat(body): Update Payload to be a trait alias of http_body::Body (#1908)
This commit is contained in:
committed by
Sean McArthur
parent
49b12c415d
commit
79c32f8953
@@ -251,19 +251,11 @@ where
|
||||
if let Some(msg) = ready!(self.dispatch.poll_msg(cx)) {
|
||||
let (head, mut body) = msg.map_err(crate::Error::new_user_service)?;
|
||||
|
||||
// Check if the body knows its full data immediately.
|
||||
//
|
||||
// If so, we can skip a bit of bookkeeping that streaming
|
||||
// bodies need to do.
|
||||
if let Some(full) = body.__hyper_full_data(FullDataArg(())).0 {
|
||||
self.conn.write_full_msg(head, full);
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
let body_type = if body.is_end_stream() {
|
||||
self.body_rx.set(None);
|
||||
None
|
||||
} else {
|
||||
let btype = body.content_length()
|
||||
let btype = body.size_hint().exact()
|
||||
.map(BodyLength::Known)
|
||||
.or_else(|| Some(BodyLength::Unknown));
|
||||
self.body_rx.set(Some(body));
|
||||
|
||||
@@ -125,7 +125,7 @@ where
|
||||
let (head, body) = req.into_parts();
|
||||
let mut req = ::http::Request::from_parts(head, ());
|
||||
super::strip_connection_headers(req.headers_mut(), true);
|
||||
if let Some(len) = body.content_length() {
|
||||
if let Some(len) = body.size_hint().exact() {
|
||||
headers::set_content_length_if_missing(req.headers_mut(), len);
|
||||
}
|
||||
let eos = body.is_end_stream();
|
||||
|
||||
@@ -178,17 +178,17 @@ where
|
||||
}
|
||||
|
||||
match ready!(Pin::new(&mut self.stream).poll_trailers(cx)) {
|
||||
Some(Ok(trailers)) => {
|
||||
Ok(Some(trailers)) => {
|
||||
self.body_tx
|
||||
.send_trailers(trailers)
|
||||
.map_err(crate::Error::new_body_write)?;
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
Some(Err(e)) => return Poll::Ready(Err(self.on_user_err(e))),
|
||||
None => {
|
||||
Ok(None) => {
|
||||
// There were no trailers, so send an empty DATA frame...
|
||||
return Poll::Ready(self.send_eos_frame());
|
||||
}
|
||||
Err(e) => return Poll::Ready(Err(self.on_user_err(e))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,19 +289,10 @@ where
|
||||
}
|
||||
|
||||
// automatically set Content-Length from body...
|
||||
if let Some(len) = body.content_length() {
|
||||
if let Some(len) = body.size_hint().exact() {
|
||||
headers::set_content_length_if_missing(res.headers_mut(), len);
|
||||
}
|
||||
|
||||
if let Some(full) = body.__hyper_full_data(FullDataArg(())).0 {
|
||||
let mut body_tx = reply!(false);
|
||||
let buf = SendBuf(Some(full));
|
||||
body_tx
|
||||
.send_data(buf, true)
|
||||
.map_err(crate::Error::new_body_write)?;
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
|
||||
if !body.is_end_stream() {
|
||||
let body_tx = reply!(false);
|
||||
H2StreamState::Body(PipeToSendStream::new(body, body_tx))
|
||||
|
||||
Reference in New Issue
Block a user