1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#![allow(clippy::borrow_interior_mutable_const, clippy::type_complexity)]

//! Static files support
use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

use actix_service::boxed::{self, BoxServiceFactory};
use actix_service::{IntoServiceFactory, ServiceFactory, ServiceFactoryExt};
use actix_web::dev::{
  AppService, HttpServiceFactory, ResourceDef, ServiceRequest, ServiceResponse,
};
use actix_web::error::Error as ActixError;
use actix_web::guard::Guard;
use futures_util::future::LocalBoxFuture;

use path_context::PathContext;
use service::FilesService;
use tokio::sync::RwLock;

use self::service::FilesServiceInner;

pub mod directory;
mod named_ext;
mod pages;
mod path;
pub mod path_context;
mod pathbuf;
mod service;

type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, ActixError, ()>;

/// Static files handling
///
/// `Files` service must be registered with `App::service()` method.
///
/// ```rust
/// use std::{
///   convert::TryInto,
///   sync::Arc,
/// };
/// use actix_web::App;
/// use espresso::{
///   files::Files,
///   config::ServerConfig,
/// };
/// use tokio::sync::RwLock;
///
/// let mut server_config = ServerConfig::default();
///
/// let serve_dir = Arc::new(RwLock::new(Some(".".into())));
/// let root_path_context = Arc::new((&server_config).try_into().unwrap());
/// let path_contexts = Arc::new(vec![]);
///
/// let app = App::new()
///   .service(Files::new(
///     "/static",
///     serve_dir,
///     root_path_context,
///     path_contexts,
///   ));
/// ```
pub struct Files {
  path: String,
  directory: Arc<RwLock<Option<PathBuf>>>,
  root_path_context: Arc<PathContext>,
  #[allow(clippy::rc_buffer)]
  path_contexts: Arc<Vec<PathContext>>,
  redirect_to_slash: bool,
  default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
  use_guards: Option<Rc<dyn Guard>>,
  guards: Vec<Rc<dyn Guard>>,
}

impl Clone for Files {
  fn clone(&self) -> Self {
    Self {
      directory: self.directory.clone(),
      redirect_to_slash: self.redirect_to_slash,
      default: self.default.clone(),
      path: self.path.clone(),
      use_guards: self.use_guards.clone(),
      root_path_context: self.root_path_context.clone(),
      path_contexts: self.path_contexts.clone(),
      guards: self.guards.clone(),
    }
  }
}

impl Files {
  /// Create new `Files` instance for specified base directory.
  ///
  /// `File` uses `ThreadPool` for blocking filesystem operations.
  /// By default pool with 5x threads of available cpus is used.
  /// Pool size can be changed by setting `ACTIX_THREADPOOL` environment variable.
  #[allow(clippy::rc_buffer)]
  pub fn new(
    path: &str,
    directory: Arc<RwLock<Option<PathBuf>>>,
    root_path_context: Arc<PathContext>,
    path_contexts: Arc<Vec<PathContext>>,
  ) -> Files {
    // let orig_dir = dir.into();
    // let dir = match orig_dir.canonicalize() {
    //   Ok(canon_dir) => canon_dir,
    //   Err(_) => {
    //     log::error!("Specified path is not a directory: {:?}", orig_dir);
    //     PathBuf::new()
    //   }
    // };

    Files {
      path: path.trim_end_matches('/').to_string(),
      directory,
      redirect_to_slash: false,
      default: Rc::new(RefCell::new(None)),
      use_guards: None,
      guards: vec![],
      root_path_context,
      path_contexts,
    }
  }

  /// Redirects to a slash-ended path when browsing a directory.
  ///
  /// By default never redirect.
  pub fn redirect_to_slash_directory(mut self) -> Self {
    self.redirect_to_slash = true;
    self
  }

  /// Adds a routing guard.
  ///
  /// Use this to allow multiple chained file services that respond to strictly different
  /// properties of a request. Due to the way routing works, if a guard check returns true and the
  /// request starts being handled by the file service, it will not be able to back-out and try
  /// the next service, you will simply get a 404 (or 405) error response.
  ///
  /// To allow `POST` requests to retrieve files, see [`Files::use_guards`].
  ///
  /// # Examples
  /// ```
  /// use std::{
  ///   convert::TryInto,
  ///   sync::Arc,
  /// };
  /// use actix_web::{guard::Header, App};
  /// use espresso::{
  ///   files::Files,
  ///   config::ServerConfig,
  /// };
  /// use tokio::sync::RwLock;
  ///
  /// let mut server_config = ServerConfig::default();
  ///
  /// let serve_dir = Arc::new(RwLock::new(Some(".".into())));
  /// let root_path_context = Arc::new((&server_config).try_into().unwrap());
  /// let path_contexts = Arc::new(vec![]);
  ///
  /// App::new().service(
  ///     Files::new("/", serve_dir, root_path_context, path_contexts)
  ///         .guard(Header("Host", "example.com"))
  /// );
  /// ```
  pub fn guard<G: Guard + 'static>(mut self, guard: G) -> Self {
    self.guards.push(Rc::new(guard));
    self
  }

  /// Specifies custom guards to use for directory listings and files.
  ///
  /// Default behaviour allows GET and HEAD.
  #[inline]
  pub fn method_guard<G: Guard + 'static>(mut self, guards: G) -> Self {
    self.use_guards = Some(Rc::new(guards));
    self
  }

  /// Sets default handler which is used when no matched file could be found.
  pub fn default_handler<F, U>(mut self, f: F) -> Self
  where
    F: IntoServiceFactory<U, ServiceRequest>,
    U: ServiceFactory<
        ServiceRequest,
        Config = (),
        Response = ServiceResponse,
        Error = actix_web::error::Error,
      > + 'static,
  {
    // create and configure default resource
    self.default = Rc::new(RefCell::new(Some(Rc::new(boxed::factory(
      f.into_factory().map_init_err(|_| ()),
    )))));

    self
  }
}

impl HttpServiceFactory for Files {
  fn register(mut self, config: &mut AppService) {
    let guards = if self.guards.is_empty() {
      None
    } else {
      let guards = std::mem::take(&mut self.guards);
      Some(
        guards
          .into_iter()
          .map(|guard| -> Box<dyn Guard> { Box::new(guard) })
          .collect::<Vec<_>>(),
      )
    };

    if self.default.borrow().is_none() {
      *self.default.borrow_mut() = Some(config.default_service());
    }

    let rdef = if config.is_root() {
      ResourceDef::root_prefix(&self.path)
    } else {
      ResourceDef::prefix(&self.path)
    };

    config.register_service(rdef, guards, self, None)
  }
}

impl ServiceFactory<ServiceRequest> for Files {
  type Response = ServiceResponse;
  type Error = ActixError;
  type Config = ();
  type Service = FilesService;
  type InitError = ();
  type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;

  fn new_service(&self, _: ()) -> Self::Future {
    let mut inner = FilesServiceInner::new(
      self.directory.clone(),
      self.redirect_to_slash,
      None,
      self.root_path_context.clone(),
      self.path_contexts.clone(),
      self.use_guards.clone(),
    );

    if let Some(ref default) = *self.default.borrow() {
      let fut = default.new_service(());

      Box::pin(async {
        match fut.await {
          Ok(default) => {
            inner.default = Some(default);
            Ok(FilesService(Rc::new(inner)))
          }
          Err(_) => Err(()),
        }
      })
    } else {
      Box::pin(async move { Ok(FilesService(Rc::new(inner))) })
    }
  }
}

#[cfg(test)]
mod tests {
  use std::collections::{HashMap, HashSet};
  use std::convert::TryInto;
  use std::fs;

  use super::*;
  use crate::config::{ContentDispositionConfig, IndexStrategyConfig, ServerConfig};
  use actix_web::guard;

  use actix_web::http::{header, Method, StatusCode};
  use actix_web::test::{self, TestRequest};
  use actix_web::App;
  use bytes::Bytes;

  fn serve_dir<T: Into<PathBuf>>(path: T) -> Arc<RwLock<Option<PathBuf>>> {
    Arc::new(RwLock::new(Some(path.into())))
  }

  #[actix_rt::test]
  async fn test_mime_override() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::IndexFiles {
        filenames: HashSet::from(["Cargo.toml".to_owned()]),
      }),
      mime_disposition: Some(HashMap::from([(
        "text/x-toml".to_owned(),
        ContentDispositionConfig::Attachment,
      )])),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;

    let request = TestRequest::get().uri("/").to_request();
    let response = test::call_service(&srv, request).await;
    assert_eq!(response.status(), StatusCode::OK);

    let content_disposition = response
      .headers()
      .get(header::CONTENT_DISPOSITION)
      .expect("To have CONTENT_DISPOSITION");
    let content_disposition = content_disposition
      .to_str()
      .expect("Convert CONTENT_DISPOSITION to str");
    assert_eq!(content_disposition, "attachment; filename=\"Cargo.toml\"");
  }

  #[actix_rt::test]
  async fn test_named_file_ranges_status_code() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::IndexFiles {
        filenames: ["Cargo.toml".to_owned()].iter().cloned().collect(),
      }),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/test",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;

    // Valid range header
    let request = TestRequest::get()
      .uri("/t%65st/Cargo.toml")
      .append_header((header::RANGE, "bytes=10-20"))
      .to_request();
    let response = test::call_service(&srv, request).await;
    assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);

    // Invalid range header
    let request = TestRequest::get()
      .uri("/t%65st/Cargo.toml")
      .append_header((header::RANGE, "bytes=1-0"))
      .to_request();
    let response = test::call_service(&srv, request).await;

    assert_eq!(response.status(), StatusCode::RANGE_NOT_SATISFIABLE);
  }

  #[actix_rt::test]
  async fn test_named_file_content_range_headers() {
    let srv = actix_test::start(|| {
      let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
      let path_contexts = Arc::new(vec![]);

      App::new().service(Files::new(
        "/",
        serve_dir("."),
        root_path_context,
        path_contexts,
      ))
    });

    // Valid range header
    let response = srv
      .get("/tests/test.binary")
      .append_header((header::RANGE, "bytes=10-20"))
      .send()
      .await
      .unwrap();
    let content_range = response.headers().get(header::CONTENT_RANGE).unwrap();
    assert_eq!(content_range.to_str().unwrap(), "bytes 10-20/100");

    // Invalid range header
    let response = srv
      .get("/tests/test.binary")
      .append_header((header::RANGE, "bytes=10-5"))
      .send()
      .await
      .unwrap();
    let content_range = response.headers().get(header::CONTENT_RANGE).unwrap();
    assert_eq!(content_range.to_str().unwrap(), "bytes */100");
  }

  #[actix_rt::test]
  async fn test_named_file_content_length_headers() {
    let srv = actix_test::start(|| {
      let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
      let path_contexts = Arc::new(vec![]);

      App::new().service(Files::new(
        "/",
        serve_dir("."),
        root_path_context,
        path_contexts,
      ))
    });

    // Valid range header
    let response = srv
      .get("/tests/test.binary")
      .append_header((header::RANGE, "bytes=10-20"))
      .send()
      .await
      .unwrap();
    let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
    assert_eq!(content_length.to_str().unwrap(), "11");

    // Valid range header, starting from 0
    let response = srv
      .get("/tests/test.binary")
      .append_header((header::RANGE, "bytes=0-20"))
      .send()
      .await
      .unwrap();
    let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
    assert_eq!(content_length.to_str().unwrap(), "21");

    // Without range header
    let mut response = srv.get("/tests/test.binary").send().await.unwrap();
    let content_length = response.headers().get(header::CONTENT_LENGTH).unwrap();
    assert_eq!(content_length.to_str().unwrap(), "100");

    // Should be no transfer-encoding
    let transfer_encoding = response.headers().get(header::TRANSFER_ENCODING);
    assert!(transfer_encoding.is_none());

    // Check file contents
    let bytes = response.body().await.unwrap();
    let data = Bytes::from(fs::read("tests/test.binary").unwrap());

    assert_eq!(bytes, data);
  }

  #[actix_rt::test]
  async fn test_head_content_length_headers() {
    let srv = actix_test::start(|| {
      let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
      let path_contexts = Arc::new(vec![]);

      App::new().service(Files::new(
        "/",
        serve_dir("."),
        root_path_context,
        path_contexts,
      ))
    });

    let response = srv.head("/tests/test.binary").send().await.unwrap();

    let content_length = response
      .headers()
      .get(header::CONTENT_LENGTH)
      .unwrap()
      .to_str()
      .unwrap();

    assert_eq!(content_length, "100");
  }

  #[actix_rt::test]
  async fn test_static_files_with_spaces() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::IndexFiles {
        filenames: ["Cargo.toml".to_owned()].iter().cloned().collect(),
      }),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;
    let request = TestRequest::get()
      .uri("/tests/test%20space.binary")
      .to_request();
    let response = test::call_service(&srv, request).await;
    assert_eq!(response.status(), StatusCode::OK);

    let bytes = test::read_body(response).await;
    let data = Bytes::from(fs::read("tests/test space.binary").unwrap());
    assert_eq!(bytes, data);
  }

  #[actix_rt::test]
  async fn test_files_not_allowed() {
    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().default_service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;

    let req = TestRequest::default()
      .uri("/Cargo.toml")
      .method(Method::POST)
      .to_request();

    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);

    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().default_service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;
    let req = TestRequest::default()
      .method(Method::PUT)
      .uri("/Cargo.toml")
      .to_request();
    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
  }

  #[actix_rt::test]
  async fn test_files_guards() {
    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(
      Files::new("/", serve_dir("."), root_path_context, path_contexts).method_guard(guard::Post()),
    ))
    .await;

    let req = TestRequest::default()
      .uri("/Cargo.toml")
      .method(Method::POST)
      .to_request();

    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::OK);
  }

  #[actix_rt::test]
  async fn test_static_files() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::AlwaysShowListing),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;
    let req = TestRequest::with_uri("/tests/test.png").to_request();

    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::OK);

    let bytes = test::read_body(resp).await;

    let data = Bytes::from(fs::read("tests/test.png").unwrap());
    assert_eq!(bytes, data);
  }

  #[actix_rt::test]
  async fn test_static_files_percent_encoded() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::AlwaysShowListing),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;
    let req = TestRequest::with_uri("/%43argo.toml").to_request();

    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::OK);
  }

  #[actix_rt::test]
  async fn test_static_files_with_missing_path() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::AlwaysShowListing),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;
    let req = TestRequest::with_uri("/missing").to_request();

    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::NOT_FOUND);
  }

  #[actix_rt::test]
  async fn test_static_files_without_index_strategy() {
    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;

    let req = TestRequest::default().to_request();
    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::NOT_FOUND);
  }

  #[actix_rt::test]
  async fn test_static_files_with_listing_index_strategy() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::AlwaysShowListing),
      ..ServerConfig::default()
    };

    let root_path_context = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let srv = test::init_service(App::new().default_service(Files::new(
      "/",
      serve_dir("."),
      root_path_context,
      path_contexts,
    )))
    .await;

    let req = TestRequest::with_uri("/tests").to_request();
    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::OK);
    assert_eq!(
      resp.headers().get(header::CONTENT_TYPE).unwrap(),
      "text/html; charset=utf-8"
    );

    let bytes = test::read_body(resp).await;
    assert!(format!("{:?}", bytes).contains("/tests/test.png"));
  }

  #[actix_rt::test]
  async fn test_redirect_to_slash_directory() {
    let server_config = ServerConfig {
      index_strategy: Some(IndexStrategyConfig::IndexFiles {
        filenames: ["test.png".to_owned()].iter().cloned().collect(),
      }),
      ..ServerConfig::default()
    };

    let root_path_context: Arc<PathContext> = Arc::new((&server_config).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    // should redirect if index present
    let srv = test::init_service(
      App::new().service(
        Files::new("/", serve_dir("."), root_path_context, path_contexts)
          .redirect_to_slash_directory(),
      ),
    )
    .await;
    let req = TestRequest::with_uri("/tests").to_request();
    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::FOUND);

    // should not redirect if the path is wrong
    let req = TestRequest::with_uri("/not_existing").to_request();
    let resp = test::call_service(&srv, req).await;
    assert_eq!(resp.status(), StatusCode::NOT_FOUND);
  }

  #[actix_rt::test]
  async fn test_static_files_bad_directory() {
    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let _st: Files = Files::new("/", serve_dir("missing"), root_path_context, path_contexts);

    let root_path_context = Arc::new((&ServerConfig::default()).try_into().unwrap());
    let path_contexts = Arc::new(vec![]);

    let _st: Files = Files::new(
      "/",
      serve_dir("Cargo.toml"),
      root_path_context,
      path_contexts,
    );
  }
}