From d24d5534f4d69ba2aaf29f8f2c07d4001646922a Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 2 Nov 2016 17:47:00 +0100 Subject: [PATCH] Return a 404 when a file isn't found. --- examples/static_files/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/static_files/src/main.rs b/examples/static_files/src/main.rs index 34ed8c94..a9fba7cf 100644 --- a/examples/static_files/src/main.rs +++ b/examples/static_files/src/main.rs @@ -6,7 +6,8 @@ extern crate rocket; use std::io; use std::path::{Path, PathBuf}; -use rocket::response::NamedFile; +use rocket::response::{NamedFile, Failure}; +use rocket::http::StatusCode::NotFound; #[get("/")] fn index() -> io::Result { @@ -14,8 +15,8 @@ fn index() -> io::Result { } #[get("/")] -fn files(file: PathBuf) -> io::Result { - NamedFile::open(Path::new("static/").join(file)) +fn files(file: PathBuf) -> Result { + NamedFile::open(Path::new("static/").join(file)).map_err(|_| Failure(NotFound)) } fn main() {