Skip to content

Commit 9173116

Browse files
committed
Return http 404 when match try-file-404
1 parent f603489 commit 9173116

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use iron::headers::{AcceptEncoding, ContentEncoding, Encoding, QualityItem};
1818
use iron::method;
1919
use iron::modifiers::Redirect;
2020
use iron::status;
21+
use iron::status::Status;
2122
use iron::{Chain, Handler, Iron, IronError, IronResult, Request, Response, Set};
2223
use iron_cors::CorsMiddleware;
2324
use lazy_static::lazy_static;
@@ -509,7 +510,7 @@ impl Handler for MainHandler {
509510
io::ErrorKind::NotFound => {
510511
if let Some(ref p) = self.try_file_404 {
511512
if Some(true) == fs::metadata(p).ok().map(|meta| meta.is_file()) {
512-
return self.send_file(req, p);
513+
return self.send_file(req, p, Some(status::NotFound));
513514
}
514515
}
515516
status::NotFound
@@ -527,7 +528,7 @@ impl Handler for MainHandler {
527528
.collect();
528529
self.list_directory(req, &fs_path, &path_prefix, &self.base_url[..])
529530
} else {
530-
self.send_file(req, &fs_path)
531+
self.send_file(req, &fs_path, None)
531532
}
532533
}
533534
}
@@ -776,7 +777,7 @@ impl MainHandler {
776777
if filename == *fname {
777778
// Automatic render index page
778779
fs_path.push(filename);
779-
return self.send_file(req, &fs_path);
780+
return self.send_file(req, &fs_path, None);
780781
}
781782
}
782783
}
@@ -884,7 +885,12 @@ impl MainHandler {
884885
Ok(resp)
885886
}
886887

887-
fn send_file<P: AsRef<Path>>(&self, req: &Request, path: P) -> IronResult<Response> {
888+
fn send_file<P: AsRef<Path>>(
889+
&self,
890+
req: &Request,
891+
path: P,
892+
status: Option<Status>,
893+
) -> IronResult<Response> {
888894
use filetime::FileTime;
889895
use iron::headers::{
890896
AcceptRanges, ByteRangeSpec, ContentLength, ContentRange, ContentRangeSpec, ETag,
@@ -907,7 +913,7 @@ impl MainHandler {
907913
modified.nsec
908914
));
909915

910-
let mut resp = Response::with(status::Ok);
916+
let mut resp = Response::with(status.unwrap_or(status::Ok));
911917
if self.range {
912918
resp.headers.set(AcceptRanges(vec![RangeUnit::Bytes]));
913919
}

0 commit comments

Comments
 (0)