diff options
Diffstat (limited to '')
-rw-r--r-- | src/args.rs | 6 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/listing.rs | 9 | ||||
-rw-r--r-- | src/renderer.rs | 2 |
4 files changed, 20 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index e42d2ff..7502d9f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -294,6 +294,12 @@ pub struct CliArgs { /// Enable README.md rendering in directories #[arg(long, env = "MINISERVE_README")] pub readme: bool, + + /// Disable indexing + /// This will prevent miniserve from generating directory listings + /// and will return a 404 instead. + #[arg(long, env = "MINISERVE_DISABLE_INDEXING")] + pub disable_indexing: bool, } /// Checks whether an interface is valid, i.e. it can be parsed into an IP address diff --git a/src/config.rs b/src/config.rs index 43414b2..3643502 100644 --- a/src/config.rs +++ b/src/config.rs @@ -146,6 +146,9 @@ pub struct MiniserveConfig { /// If enabled, render the readme from the current directory pub readme: bool, + /// If enabled, indexing is disabled. + pub disable_indexing: bool, + /// If set, use provided rustls config for TLS #[cfg(feature = "tls")] pub tls_rustls_config: Option<rustls::ServerConfig>, @@ -311,6 +314,7 @@ impl MiniserveConfig { hide_theme_selector: args.hide_theme_selector, show_wget_footer: args.show_wget_footer, readme: args.readme, + disable_indexing: args.disable_indexing, tls_rustls_config: tls_rustls_server_config, compress_response: args.compress_response, }) diff --git a/src/listing.rs b/src/listing.rs index faa0918..a8668e3 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -376,6 +376,15 @@ pub fn directory_listing( .body(actix_web::body::BodyStream::new(rx)), )) } else { + if conf.disable_indexing { + return Ok(ServiceResponse::new( + req.clone(), + HttpResponse::NotFound() + .content_type(mime::TEXT_PLAIN_UTF_8) + .body("File not found."), + )); + } + Ok(ServiceResponse::new( req.clone(), HttpResponse::Ok().content_type(mime::TEXT_HTML_UTF_8).body( diff --git a/src/renderer.rs b/src/renderer.rs index 3b62704..b691bca 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -687,7 +687,7 @@ pub fn render_error( p { (error) } } // WARN don't expose random route! - @if conf.route_prefix.is_empty() { + @if conf.route_prefix.is_empty() && !conf.disable_indexing { div.error-nav { a.error-back href=(return_address) { "Go back to file listing" |