From 75c0a61bf948d3591db5cc53913898e376fabe09 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Wed, 21 Dec 2022 19:00:54 +0100 Subject: [PATCH] fix panic if invalid url --- lib/src/embed/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/embed/mod.rs b/lib/src/embed/mod.rs index e8f6dcc..0e6c572 100644 --- a/lib/src/embed/mod.rs +++ b/lib/src/embed/mod.rs @@ -1,7 +1,7 @@ use std::io::Cursor; -use rust_embed::RustEmbed; +use rust_embed::{EmbeddedFile, RustEmbed}; use rocket::{Data, Request, Response, Route}; -use rocket::http::{ContentType, Method}; +use rocket::http::{ContentType, Method, Status}; use rocket::http::uri::{Segments}; use rocket::http::uri::fmt::Path; use rocket::route::{Handler, Outcome}; @@ -13,8 +13,7 @@ struct Asset; #[cfg(feature = "static")] #[derive(Clone)] -pub struct CustomHandler { -} +pub struct CustomHandler {} #[cfg(feature = "static")] impl Into> for CustomHandler { @@ -38,8 +37,12 @@ impl Handler for CustomHandler { path }; - let file_content = - ::get(path.to_string_lossy().as_ref()).unwrap(); + let file_content = ::get(path.to_string_lossy().as_ref()); + let file_content = match file_content { + None => return Outcome::Failure(Status::NotFound), + Some(c) => c + }; + let content_type: ContentType = path .extension() .map(|x| x.to_string_lossy())