Don't preallocate in 'Body.into_bytes()'.

This commit is contained in:
Sergio Benitez 2018-01-19 11:20:01 -08:00
parent f04dc195bd
commit 72d2ccc2a5
1 changed files with 2 additions and 5 deletions

View File

@ -63,11 +63,8 @@ impl<T: io::Read> Body<T> {
/// Attepts to read `self` into a `Vec` and returns it. If reading fails, /// Attepts to read `self` into a `Vec` and returns it. If reading fails,
/// returns `None`. /// returns `None`.
pub fn into_bytes(self) -> Option<Vec<u8>> { pub fn into_bytes(self) -> Option<Vec<u8>> {
let (mut body, mut vec) = match self { let mut vec = Vec::new();
Body::Sized(b, size) => (b, Vec::with_capacity(size as usize)), let mut body = self.into_inner();
Body::Chunked(b, _) => (b, Vec::new())
};
if let Err(e) = body.read_to_end(&mut vec) { if let Err(e) = body.read_to_end(&mut vec) {
error_!("Error reading body: {:?}", e); error_!("Error reading body: {:?}", e);
return None; return None;