From 80a1723644ae80a4db94f0a6813399abde1e995b Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Tue, 18 May 2021 17:14:28 +0200 Subject: [PATCH] refactor: enable --directory-listing (-z) option --- src/handler.rs | 9 ++++++--- src/server.rs | 12 +++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/handler.rs b/src/handler.rs index 7fa45c2..4a9ec48 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -5,12 +5,15 @@ use crate::{compression, control_headers, static_files}; use crate::{error::Result, error_page}; /// Main server request handler. -pub async fn handle_request(base: &Path, req: &Request) -> Result> { +pub async fn handle_request( + base: &Path, + dir_listing: bool, + req: &Request, +) -> Result> { let headers = req.headers(); let method = req.method(); - // TODO: replace `dir_listing` arg with the corresponding config option - match static_files::handle_request(method, headers, base, req.uri().path(), true).await { + match static_files::handle_request(method, headers, base, req.uri().path(), dir_listing).await { Ok(resp) => { // Compression on demand based on`Accept-Encoding` header let mut resp = compression::auto(method, headers, resp)?; diff --git a/src/server.rs b/src/server.rs index 25c47e9..ae40d51 100644 --- a/src/server.rs +++ b/src/server.rs @@ -57,7 +57,6 @@ impl Server { logger::init(&opts.log_level)?; tracing::info!("runtime worker threads {}", self.threads); - tracing::info!("runtime max blocking threads {}", self.threads); let ip = opts.host.parse::()?; let addr = SocketAddr::from((ip, opts.port)); @@ -76,6 +75,9 @@ impl Server { // TODO: CORS support + // Directory listing option + let dir_listing = opts.directory_listing.unwrap_or_default(); + // Spawn a new Tokio asynchronous server task with its given options let threads = self.threads; @@ -91,7 +93,9 @@ impl Server { async move { Ok::<_, error::Error>(service_fn(move |req| { let root_dir = root_dir.clone(); - async move { handler::handle_request(root_dir.as_ref(), &req).await } + async move { + handler::handle_request(root_dir.as_ref(), dir_listing, &req).await + } })) } }); @@ -125,7 +129,9 @@ impl Server { async move { Ok::<_, error::Error>(service_fn(move |req| { let root_dir = root_dir.clone(); - async move { handler::handle_request(root_dir.as_ref(), &req).await } + async move { + handler::handle_request(root_dir.as_ref(), dir_listing, &req).await + } })) } }); -- libgit2 1.7.2