diff options
Diffstat (limited to '')
-rw-r--r-- | src/args.rs | 4 | ||||
-rw-r--r-- | src/file_upload.rs | 12 | ||||
-rw-r--r-- | src/listing.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 17 | ||||
-rw-r--r-- | tests/auth.rs | 2 | ||||
-rw-r--r-- | tests/cli.rs | 2 | ||||
-rw-r--r-- | tests/navigation.rs | 3 | ||||
-rw-r--r-- | tests/serve_request.rs | 8 |
8 files changed, 32 insertions, 27 deletions
diff --git a/src/args.rs b/src/args.rs index 78340dd..49fe276 100644 --- a/src/args.rs +++ b/src/args.rs @@ -31,7 +31,7 @@ struct CLIArgs { /// /// Normally, when miniserve serves a directory, it creates a listing for that directory. /// However, if a directory contains this file, miniserve will serve that file instead. - #[structopt(long, parse(from_os_str), name="index_file")] + #[structopt(long, parse(from_os_str), name = "index_file")] index: Option<PathBuf>, /// Port to use @@ -83,7 +83,7 @@ struct CLIArgs { /// Enable overriding existing files during file upload #[structopt(short = "o", long = "overwrite-files")] overwrite_files: bool, - + /// Disable archive generation #[structopt(short = "r", long = "disable-archives")] disable_archives: bool, diff --git a/src/file_upload.rs b/src/file_upload.rs index af4fcf2..6e49f20 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -120,7 +120,7 @@ fn handle_multipart( pub fn upload_file( req: &HttpRequest<crate::MiniserveConfig>, default_color_scheme: ColorScheme, - uses_random_route: bool + uses_random_route: bool, ) -> FutureResponse<HttpResponse> { let return_path = if let Some(header) = req.headers().get(header::REFERER) { header.to_str().unwrap_or("/").to_owned() @@ -147,7 +147,7 @@ pub fn upload_file( query_params.order, color_scheme, default_color_scheme, - uses_random_route + uses_random_route, )); } }; @@ -167,7 +167,7 @@ pub fn upload_file( query_params.order, color_scheme, default_color_scheme, - uses_random_route + uses_random_route, )); } }; @@ -187,7 +187,7 @@ pub fn upload_file( query_params.order, color_scheme, default_color_scheme, - uses_random_route + uses_random_route, )); } }; @@ -212,7 +212,7 @@ pub fn upload_file( query_params.order, color_scheme, default_color_scheme, - uses_random_route + uses_random_route, ), }), ) @@ -228,7 +228,7 @@ fn create_error_response( sorting_order: Option<SortingOrder>, color_scheme: ColorScheme, default_color_scheme: ColorScheme, - uses_random_route: bool + uses_random_route: bool, ) -> FutureResult<HttpResponse, actix_web::error::Error> { errors::log_error_chain(description.to_string()); future::ok( diff --git a/src/listing.rs b/src/listing.rs index 256e062..d28824c 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -1,5 +1,5 @@ -use actix_web::{fs, Body, FromRequest, HttpRequest, HttpResponse, Query, Result}; use actix_web::http::StatusCode; +use actix_web::{fs, Body, FromRequest, HttpRequest, HttpResponse, Query, Result}; use bytesize::ByteSize; use futures::Stream; use htmlescape::encode_minimal as escape_html_entity; @@ -172,8 +172,7 @@ pub fn directory_listing<S>( Err(_) => continue, }; // show file url as relative to static path - let file_url = - utf8_percent_encode(&p.to_string_lossy(), FRAGMENT).to_string(); + let file_url = utf8_percent_encode(&p.to_string_lossy(), FRAGMENT).to_string(); // " -- " & -- & ' -- ' < -- < > -- > let file_name = escape_html_entity(&entry.file_name().to_string_lossy()); @@ -265,9 +264,9 @@ pub fn directory_listing<S>( default_color_scheme, false, false, - ).into_string() - ) - ); + ) + .into_string(), + )); } log::info!( "Creating an archive ({extension}) of {path}...", diff --git a/src/main.rs b/src/main.rs index 2885c59..a1ee303 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ pub struct MiniserveConfig { /// Enable upload to override existing files pub overwrite_files: bool, - + /// If false, creation of archives is disabled pub archives: bool, } @@ -142,8 +142,10 @@ fn run() -> Result<(), ContextualError> { if let Some(index_path) = &miniserve_config.index { let has_index: std::path::PathBuf = [&canon_path, index_path].iter().collect(); if !has_index.exists() { - - println!("{warning} The provided index file could not be found.", warning=Color::RGB(255, 192, 0).paint("Notice:").bold()); + println!( + "{warning} The provided index file could not be found.", + warning = Color::RGB(255, 192, 0).paint("Notice:").bold() + ); } } let path_string = canon_path.to_string_lossy(); @@ -266,7 +268,7 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> { Some( fs::StaticFiles::new(path) .expect("Failed to setup static file handler") - .index_file(index_file.to_string_lossy()) + .index_file(index_file.to_string_lossy()), ) } else { let u_r = upload_route.clone(); @@ -283,7 +285,7 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> { random_route.clone(), default_color_scheme, u_r.clone(), - archives_enabled + archives_enabled, ) }) .default_handler(error_404), @@ -300,8 +302,9 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> { let default_color_scheme = app.state().default_color_scheme; // Allow file upload app.resource(&upload_route, move |r| { - r.method(Method::POST) - .f(move |file| file_upload::upload_file(file, default_color_scheme, uses_random_route)) + r.method(Method::POST).f(move |file| { + file_upload::upload_file(file, default_color_scheme, uses_random_route) + }) }) // Handle directories .handler(&full_route, s) diff --git a/tests/auth.rs b/tests/auth.rs index 4cabb77..255c09f 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -4,8 +4,8 @@ use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; use fixtures::{port, tmpdir, Error, FILES}; use pretty_assertions::assert_eq; -use reqwest::StatusCode; use reqwest::blocking::Client; +use reqwest::StatusCode; use rstest::rstest; use select::document::Document; use select::predicate::Text; diff --git a/tests/cli.rs b/tests/cli.rs index 5bd7d96..e09473d 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,9 +1,9 @@ mod fixtures; use assert_cmd::prelude::*; -use structopt::clap::{crate_name, crate_version}; use fixtures::Error; use std::process::Command; +use structopt::clap::{crate_name, crate_version}; #[test] /// Show help and exit. diff --git a/tests/navigation.rs b/tests/navigation.rs index 224f100..7320f06 100644 --- a/tests/navigation.rs +++ b/tests/navigation.rs @@ -52,7 +52,8 @@ fn can_navigate_into_dirs_and_back(tmpdir: TempDir, port: u16) -> Result<(), Err let initial_parsed = Document::from_read(initial_body)?; for &directory in DIRECTORIES { let dir_elem = get_link_from_text(&initial_parsed, &directory).expect("Dir not found."); - let body = reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?; + let body = + reqwest::blocking::get(&format!("{}{}", base_url, dir_elem))?.error_for_status()?; let parsed = Document::from_read(body)?; let back_link = get_link_from_text(&parsed, "Parent directory").expect("Back link not found."); diff --git a/tests/serve_request.rs b/tests/serve_request.rs index 9c30bb8..5761a65 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -41,7 +41,8 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( sleep(Duration::from_secs(1)); - let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())? + .error_for_status()?; let parsed = Document::from_read(body)?; for &file in FILES { assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); @@ -51,8 +52,9 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( .find(|x: &Node| x.text() == directory) .next() .is_some()); - let dir_body = reqwest::blocking::get(format!("http://localhost:{}/{}", port, directory).as_str())? - .error_for_status()?; + let dir_body = + reqwest::blocking::get(format!("http://localhost:{}/{}", port, directory).as_str())? + .error_for_status()?; let dir_body_parsed = Document::from_read(dir_body)?; for &file in FILES { assert!(dir_body_parsed |