Remove useless unsafe code

This commit is contained in:
Pierre HUBERT 2022-04-03 14:03:40 +02:00
parent 673001ed36
commit 8fd0981e78

View File

@ -57,8 +57,6 @@ impl Args {
}
}
static mut ARGS: Option<Args> = None;
struct NewFile {
path: PathBuf,
bytes: Vec<u8>,
@ -219,8 +217,6 @@ async fn main() -> std::io::Result<()> {
panic!("Specified files path does not exists!");
}
unsafe { ARGS = Some(args.clone()); }
HttpServer::new(move || {
App::new()
@ -238,7 +234,8 @@ async fn main() -> std::io::Result<()> {
.default_handler(fn_service(|req: ServiceRequest| async {
let (req, _) = req.into_parts();
if let Some(h) = unsafe { ARGS.as_ref().unwrap() }.default_handler_path().as_ref() {
let args: &web::Data<Args> = req.app_data().unwrap();
if let Some(h) = args.default_handler_path() {
let file = NamedFile::open_async(h).await?;
let res = file.into_response(&req);
Ok(ServiceResponse::new(req, res))