Skip to content

Commit

Permalink
[Changed] StaticFilesHandler to always response Connection: close.
Browse files Browse the repository at this point in the history
Related to this issue: nickel-org#326
  • Loading branch information
robin committed Jan 30, 2017
1 parent 9c08945 commit 9b7b06d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/static_files_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::ErrorKind::NotFound;
use std::fs;

use hyper::method::Method::{Get, Head};
use hyper::header::Connection;

use status::StatusCode;
use request::Request;
Expand Down Expand Up @@ -58,7 +59,7 @@ impl StaticFilesHandler {

fn with_file<'a, 'b, D, P>(&self,
relative_path: Option<P>,
res: Response<'a, D>)
mut res: Response<'a, D>)
-> MiddlewareResult<'a, D> where P: AsRef<Path> {
if let Some(path) = relative_path {
let path = path.as_ref();
Expand All @@ -69,7 +70,10 @@ impl StaticFilesHandler {

let path = self.root_path.join(path);
match fs::metadata(&path) {
Ok(ref attr) if attr.is_file() => return res.send_file(&path),
Ok(ref attr) if attr.is_file() => {
res.set(Connection::close());
return res.send_file(&path);
},
Err(ref e) if e.kind() != NotFound => debug!("Error getting metadata \
for file '{:?}': {:?}",
path, e),
Expand Down

0 comments on commit 9b7b06d

Please sign in to comment.