Use a 'BufReader' for file-based bodies.

This commit is contained in:
Sergio Benitez 2017-09-21 18:35:33 -07:00
parent 63169599a7
commit c36701671b
2 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
use std::fs::File; use std::fs::File;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::io; use std::io::{self, BufReader};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use request::Request; 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) Ok(response)
} }
} }

View File

@ -1,5 +1,5 @@
use std::fs::File; use std::fs::File;
use std::io::Cursor; use std::io::{Cursor, BufReader};
use std::fmt; use std::fmt;
use http::{Status, ContentType}; 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`. /// Returns a response with a sized body for the file. Always returns `Ok`.
impl<'r> Responder<'r> for File { impl<'r> Responder<'r> for File {
fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> { fn respond_to(self, _: &Request) -> Result<Response<'r>, Status> {
Response::build().streamed_body(self).ok() Response::build().streamed_body(BufReader::new(self)).ok()
} }
} }