From e2fd01917041bed9e9c419fffd97e1337a01c831 Mon Sep 17 00:00:00 2001
From: Eduardo Trujillo <ed@chromabits.com>
Date: Mon, 14 Nov 2022 23:27:47 -0800
Subject: [PATCH] refactor(server): Update compression options to those
 supported in actix-web 4

---
 src/config.rs |  6 ------
 src/server.rs | 16 ++++++++++++----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index f11d271..8cd1ede 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -251,14 +251,8 @@ pub enum IndexStrategyConfig {
 pub enum CompressionConfig {
   /// Automatically select encoding based on encoding negotiation.
   Auto,
-  /// Use the Brotli algorithm.
-  Brotli,
-  /// Use a Zlib structure with the deflate algorithm.
-  Deflate,
   /// Don't use any compression.
   Disabled,
-  /// Use the Gzip algorithm.
-  Gzip,
 }
 
 impl From<IndexStrategyConfig> for IndexStrategy {
diff --git a/src/server.rs b/src/server.rs
index 98996b4..00e9e9f 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -1,5 +1,5 @@
 use crate::{
-  config::ServerConfig,
+  config::{CompressionConfig, ServerConfig},
   files::{path_context::PathContext, Files},
   thread,
   thread::ThreadHandle,
@@ -8,7 +8,7 @@ use actix_http::http::uri::InvalidUri;
 use actix_rt::Runtime;
 use actix_web::{
   dev::ServerHandle,
-  middleware::{self, Logger},
+  middleware::{self, Condition, Logger},
   App, HttpServer,
 };
 use snafu::{ResultExt, Snafu};
@@ -67,7 +67,12 @@ impl Server {
     let server_address = self.config.address;
     let serve_dir = Arc::clone(&self.serve_dir);
     let redirect_to_slash = self.config.redirect_to_slash;
-    let compression = self.config.compression.clone();
+
+    let enable_auto_compression = match self.config.compression {
+      Some(CompressionConfig::Auto) => true,
+      None => true,
+      _ => false,
+    };
 
     let root_path_context =
       Arc::new(PathContext::try_from(&self.config).context(CreatePathContext)?);
@@ -98,7 +103,10 @@ impl Server {
 
         App::new()
           .wrap(Logger::default())
-          .wrap(middleware::Compress::default())
+          .wrap(Condition::new(
+            enable_auto_compression,
+            middleware::Compress::default(),
+          ))
           .default_service(files_service)
       })
       .bind(server_address)
-- 
GitLab