1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-29 08:09:18 +02:00

various fixes to MessageBody::complete_body (#2519)

This commit is contained in:
Ali MJ Al-Nasrawy
2021-12-17 01:25:10 +03:00
committed by GitHub
parent 156cc20ac8
commit a6d5776481
2 changed files with 36 additions and 25 deletions

View File

@@ -57,27 +57,7 @@ impl MessageBody for BoxBody {
}
fn take_complete_body(&mut self) -> Bytes {
debug_assert!(
self.is_complete_body(),
"boxed type does not allow taking complete body; caller should make sure to \
call `is_complete_body` first",
);
// we do not have DerefMut access to call take_complete_body directly but since
// is_complete_body is true we should expect the entire bytes chunk in one poll_next
let waker = futures_util::task::noop_waker();
let mut cx = Context::from_waker(&waker);
match self.as_pin_mut().poll_next(&mut cx) {
Poll::Ready(Some(Ok(data))) => data,
_ => {
panic!(
"boxed type indicated it allows taking complete body but failed to \
return Bytes when polled",
);
}
}
self.0.take_complete_body()
}
}