From 72d2ccc2a5651b83f2404adcdf3da166bae4053d Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 19 Jan 2018 11:20:01 -0800 Subject: [PATCH] Don't preallocate in 'Body.into_bytes()'. --- lib/src/response/response.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/response/response.rs b/lib/src/response/response.rs index c81a6efb..70ac7d3b 100644 --- a/lib/src/response/response.rs +++ b/lib/src/response/response.rs @@ -63,11 +63,8 @@ impl Body { /// Attepts to read `self` into a `Vec` and returns it. If reading fails, /// returns `None`. pub fn into_bytes(self) -> Option> { - let (mut body, mut vec) = match self { - Body::Sized(b, size) => (b, Vec::with_capacity(size as usize)), - Body::Chunked(b, _) => (b, Vec::new()) - }; - + let mut vec = Vec::new(); + let mut body = self.into_inner(); if let Err(e) = body.read_to_end(&mut vec) { error_!("Error reading body: {:?}", e); return None;