@@ -18,6 +18,7 @@ use iron::headers::{AcceptEncoding, ContentEncoding, Encoding, QualityItem};
1818use iron:: method;
1919use iron:: modifiers:: Redirect ;
2020use iron:: status;
21+ use iron:: status:: Status ;
2122use iron:: { Chain , Handler , Iron , IronError , IronResult , Request , Response , Set } ;
2223use iron_cors:: CorsMiddleware ;
2324use 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