From c36701671bb53099cd1006445a20f81c33582f44 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 21 Sep 2017 18:35:33 -0700 Subject: [PATCH] Use a 'BufReader' for file-based bodies. --- lib/src/response/named_file.rs | 4 ++-- lib/src/response/responder.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/response/named_file.rs b/lib/src/response/named_file.rs index 42eeba64..f41391e8 100644 --- a/lib/src/response/named_file.rs +++ b/lib/src/response/named_file.rs @@ -1,6 +1,6 @@ use std::fs::File; use std::path::{Path, PathBuf}; -use std::io; +use std::io::{self, BufReader}; use std::ops::{Deref, DerefMut}; use request::Request; @@ -90,7 +90,7 @@ impl Responder<'static> for NamedFile { } } - response.set_streamed_body(self.take_file()); + response.set_streamed_body(BufReader::new(self.take_file())); Ok(response) } } diff --git a/lib/src/response/responder.rs b/lib/src/response/responder.rs index da3c8ef1..80dfeca7 100644 --- a/lib/src/response/responder.rs +++ b/lib/src/response/responder.rs @@ -1,5 +1,5 @@ use std::fs::File; -use std::io::Cursor; +use std::io::{Cursor, BufReader}; use std::fmt; use http::{Status, ContentType}; @@ -205,7 +205,7 @@ impl<'r> Responder<'r> for String { /// Returns a response with a sized body for the file. Always returns `Ok`. impl<'r> Responder<'r> for File { fn respond_to(self, _: &Request) -> Result, Status> { - Response::build().streamed_body(self).ok() + Response::build().streamed_body(BufReader::new(self)).ok() } }