diff options
author | Carson McManus <carson.mcmanus1@gmail.com> | 2024-01-30 14:39:43 +0000 |
---|---|---|
committer | Carson McManus <carson.mcmanus1@gmail.com> | 2024-01-30 14:39:43 +0000 |
commit | 7b5b1a0e7fec2c0577eb0dc2a93e9fde48228a67 (patch) | |
tree | d78615a5da341e8929e6372da83d2293321d7aea /src/main.rs | |
parent | tweak test assertions (diff) | |
download | miniserve-7b5b1a0e7fec2c0577eb0dc2a93e9fde48228a67.tar.gz miniserve-7b5b1a0e7fec2c0577eb0dc2a93e9fde48228a67.zip |
completely disable the listing renderer when indexing is disabled
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index ce21260..63b26da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::net::{IpAddr, SocketAddr, TcpListener}; use std::thread; use std::time::Duration; -use actix_files::NamedFile; +use actix_files::{Directory, NamedFile}; use actix_web::{ dev::{fn_service, ServiceRequest, ServiceResponse}, http::header::ContentType, @@ -354,9 +354,21 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { let base_path = conf.path.clone(); let no_symlinks = conf.no_symlinks; + if !conf.disable_indexing { + files = files + .show_files_listing() + .files_listing_renderer(listing::directory_listing); + } else { + // If indexing is disabled, we return a 404 for any directory request so we don't + // leak the directory structure. + files = files.show_files_listing().files_listing_renderer( + |_dir: &Directory, req: &HttpRequest| { + let res = HttpResponse::NotFound().body("File not found."); + Ok(ServiceResponse::new(req.clone(), res)) + }, + ); + } files - .show_files_listing() - .files_listing_renderer(listing::directory_listing) .prefer_utf8(true) .redirect_to_slash_directory() .path_filter(move |path, _| { |