mirror of https://github.com/rwf2/Rocket.git
Don't preallocate in 'Body.into_bytes()'.
This commit is contained in:
parent
f04dc195bd
commit
72d2ccc2a5
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue