index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2020-06-01 22:05:19.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2020-06-01 22:05:19.0 +00:00:00
commit
c3a7d73643a14bea4ae3f45a78fe68850f289982 [patch]
tree
1d9a1028c37238bdd669be29f79329cf8b0da670
parent
c0d28918d45f0b523cea50ebc51abb794c334334
download
c3a7d73643a14bea4ae3f45a78fe68850f289982.tar.gz

refactor: minor syntax improvements



Diff

 src/gzip.rs        |  2 +-
 src/staticfiles.rs |  9 ++++-----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/gzip.rs b/src/gzip.rs
index 2f43048..737c72a 100644
--- a/src/gzip.rs
+++ b/src/gzip.rs
@@ -20,7 +20,7 @@ impl AfterMiddleware for GzipMiddleware {

        if enable_gz && accept_gz {
            let compressed_bytes = resp.body.as_mut().map(|b| {
                let mut encoder = GzEncoder::new(Vec::new(), Compression::fast());
                let mut encoder = GzEncoder::new(vec![], Compression::fast());
                {
                    let _ = b.write_body(&mut encoder);
                }
diff --git a/src/staticfiles.rs b/src/staticfiles.rs
index 2eba414..ba32bfc 100644
--- a/src/staticfiles.rs
+++ b/src/staticfiles.rs
@@ -31,7 +31,7 @@ impl StaticFiles {
    /// Handle static files for current `StaticFiles` middleware.
    pub fn handle(&self) -> Chain {
        // Check the root directory
        let root_dir = match helpers::get_valid_dirpath(&self.opts.root_dir) {
        let root_dir = &match helpers::get_valid_dirpath(&self.opts.root_dir) {
            Err(e) => {
                error!("{}", e);
                std::process::exit(1)
@@ -40,7 +40,7 @@ impl StaticFiles {
        };

        // Check the assets directory
        let assets_dir = match helpers::get_valid_dirpath(&self.opts.assets_dir) {
        let assets_dir = &match helpers::get_valid_dirpath(&self.opts.assets_dir) {
            Err(e) => {
                error!("{}", e);
                std::process::exit(1)
@@ -49,7 +49,7 @@ impl StaticFiles {
        };

        // Get the assets directory name
        let assets_dirname = match helpers::get_dirname(&assets_dir) {
        let assets_dirname = &match helpers::get_dirname(assets_dir) {
            Err(e) => {
                error!("{}", e);
                std::process::exit(1)
@@ -59,8 +59,7 @@ impl StaticFiles {

        // Define middleware chain
        let mut chain = Chain::new(
            Staticfile::new(&root_dir, &assets_dir)
                .expect("Directory to serve files was not found"),
            Staticfile::new(root_dir, assets_dir).expect("Directory to serve files was not found"),
        );
        let one_day = Duration::new(60 * 60 * 24, 0);
        let one_year = Duration::new(60 * 60 * 24 * 365, 0);