Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl Body {
/// # Ok(()) }) }
/// ```
pub async fn into_bytes(mut self) -> crate::Result<Vec<u8>> {
let mut buf = Vec::with_capacity(1024);
let len = usize::try_from(self.len().unwrap_or(0)).status(StatusCode::PayloadTooLarge)?;
let mut buf = Vec::with_capacity(len);
self.read_to_end(&mut buf)
.await
.status(StatusCode::UnprocessableEntity)?;
Expand Down Expand Up @@ -280,9 +281,8 @@ impl Body {
/// # Ok(()) }) }
/// ```
#[cfg(feature = "serde")]
pub async fn into_json<T: DeserializeOwned>(mut self) -> crate::Result<T> {
let mut buf = Vec::with_capacity(1024);
self.read_to_end(&mut buf).await?;
pub async fn into_json<T: DeserializeOwned>(self) -> crate::Result<T> {
let buf = self.into_bytes().await?;
serde_json::from_slice(&buf).status(StatusCode::UnprocessableEntity)
}

Expand Down