diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2020-07-20 21:54:25 +0000 |
---|---|---|
committer | Sven-Hendrik Haase <svenstaro@gmail.com> | 2020-07-20 21:54:25 +0000 |
commit | b17a29472f3c418f097774fc61420a8e54de8ad1 (patch) | |
tree | fa4f927f2390a505297ceafd7e29f759bbdba86d | |
parent | Change CHANGELOG.md format to keepachangelog.com (diff) | |
download | miniserve-b17a29472f3c418f097774fc61420a8e54de8ad1.tar.gz miniserve-b17a29472f3c418f097774fc61420a8e54de8ad1.zip |
cargo fmt
-rw-r--r-- | src/args.rs | 2 | ||||
-rw-r--r-- | src/listing.rs | 15 | ||||
-rw-r--r-- | tests/qrcode.rs | 8 | ||||
-rw-r--r-- | tests/serve_request.rs | 2 |
4 files changed, 12 insertions, 15 deletions
diff --git a/src/args.rs b/src/args.rs index bf16291..8893ebd 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,7 +1,7 @@ +use port_check::free_local_port; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::path::PathBuf; use structopt::StructOpt; -use port_check::free_local_port; use crate::auth; use crate::errors::ContextualError; diff --git a/src/listing.rs b/src/listing.rs index 6181c3a..063fbf3 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -4,12 +4,12 @@ use bytesize::ByteSize; use futures::Stream; use htmlescape::encode_minimal as escape_html_entity; use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; +use qrcodegen::{QrCode, QrCodeEcc}; use serde::Deserialize; use std::io; use std::path::{Path, PathBuf}; use std::time::SystemTime; use strum_macros::{Display, EnumString}; -use qrcodegen::{QrCode, QrCodeEcc}; use crate::archive::CompressionMethod; use crate::errors::{self, ContextualError}; @@ -169,18 +169,15 @@ pub fn directory_listing<S>( // If the `qrcode` parameter is included in the url, then should respond to the QR code if let Some(url) = query_params.qrcode { let res = match QrCode::encode_text(&url, QrCodeEcc::Medium) { - Ok(qr) => { - HttpResponse::Ok() - .header("Content-Type", "image/svg+xml") - .body(qr.to_svg_string(2)) - }, + Ok(qr) => HttpResponse::Ok() + .header("Content-Type", "image/svg+xml") + .body(qr.to_svg_string(2)), Err(err) => { log::error!("URL is too long: {:?}", err); - HttpResponse::UriTooLong() - .body(Body::Empty) + HttpResponse::UriTooLong().body(Body::Empty) } }; - return Ok(res) + return Ok(res); } let mut entries: Vec<Entry> = Vec::new(); diff --git a/tests/qrcode.rs b/tests/qrcode.rs index b032267..ca98861 100644 --- a/tests/qrcode.rs +++ b/tests/qrcode.rs @@ -57,7 +57,6 @@ fn show_qrcode_element(tmpdir: TempDir, port: u16) -> Result<(), Error> { #[rstest] fn get_svg_qrcode(tmpdir: TempDir, port: u16) -> Result<(), Error> { - let mut child = Command::cargo_bin("miniserve")? .arg(tmpdir.path()) .arg("-p") @@ -69,7 +68,7 @@ fn get_svg_qrcode(tmpdir: TempDir, port: u16) -> Result<(), Error> { // Ok let resp = reqwest::blocking::get(format!("http://localhost:{}/?qrcode=test", port).as_str())?; - + assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.headers()["Content-Type"], "image/svg+xml"); let body = resp.text()?; @@ -78,8 +77,9 @@ fn get_svg_qrcode(tmpdir: TempDir, port: u16) -> Result<(), Error> { // Err let content: String = repeat_with(|| '0').take(8 * 1024).collect(); - let resp = reqwest::blocking::get(format!("http://localhost:{}/?qrcode={}", port, content).as_str())?; - + let resp = + reqwest::blocking::get(format!("http://localhost:{}/?qrcode={}", port, content).as_str())?; + assert_eq!(resp.status(), StatusCode::URI_TOO_LONG); child.kill()?; diff --git a/tests/serve_request.rs b/tests/serve_request.rs index ad9dc2c..cc0e059 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -3,13 +3,13 @@ mod fixtures; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; use fixtures::{port, tmpdir, Error, DIRECTORIES, FILES}; +use regex::Regex; use rstest::rstest; use select::document::Document; use select::node::Node; use std::process::{Command, Stdio}; use std::thread::sleep; use std::time::Duration; -use regex::Regex; #[rstest] fn serves_requests_with_no_options(tmpdir: TempDir) -> Result<(), Error> { |