fix panic if invalid url

This commit is contained in:
lukas-heiligenbrunner 2022-12-21 19:00:54 +01:00
parent 6c3ee2fbe8
commit 75c0a61bf9

View File

@ -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<Vec<Route>> for CustomHandler {
@ -38,8 +37,12 @@ impl Handler for CustomHandler {
path
};
let file_content =
<Asset as RustEmbed>::get(path.to_string_lossy().as_ref()).unwrap();
let file_content = <Asset as RustEmbed>::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())