FEATURE: remove "COMPRESS_BROTLI" optional behavior

FEATURE: remove “COMPRESS_BROTLI” optional behavior

The compress brotli functionality is no longer optional, this has worked well for years. The name of the ENV var is also confusing cause it does not have a DISCOURSE_ prefix which caused issues with the web upgrader

Brotli support is now unconditionally on

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0f9c896..69d1979 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -54,7 +54,6 @@ module ApplicationHelper
   end
 
   def is_brotli_req?
-    ENV["COMPRESS_BROTLI"] == "1" &&
     request.env["HTTP_ACCEPT_ENCODING"] =~ /br/
   end
 
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index c389ea2..03ca089 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -115,32 +115,28 @@ def gzip(path)
   raise "gzip compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
 end
 
-if ENV['COMPRESS_BROTLI']&.to_i == 1
-  # different brotli versions use different parameters
-  ver_out, _ver_err, ver_status = Open3.capture3('brotli --version')
-  if !ver_status.success?
-    # old versions of brotli don't respond to --version
-    def brotli_command(path)
-      "brotli --quality 11 --input #{path} --output #{path}.br"
-    end
-  elsif ver_out >= "brotli 1.0.0"
-    def brotli_command(path)
-      "brotli -f --quality=11 #{path} --output=#{path}.br"
-    end
-  else
-    # not sure what to do here, not expecting this
-    raise "cannot determine brotli version"
+# different brotli versions use different parameters
+ver_out, _ver_err, ver_status = Open3.capture3('brotli --version')
+if !ver_status.success?
+  # old versions of brotli don't respond to --version
+  def brotli_command(path)
+    "brotli --quality 11 --input #{path} --output #{path}.br"
   end
+elsif ver_out >= "brotli 1.0.0"
+  def brotli_command(path)
+    "brotli -f --quality=11 #{path} --output=#{path}.br"
+  end
+else
+  # not sure what to do here, not expecting this
+  raise "cannot determine brotli version"
 end
 
 def brotli(path)
-  if ENV['COMPRESS_BROTLI']&.to_i == 1
-    STDERR.puts brotli_command(path)
-    STDERR.puts `#{brotli_command(path)}`
-    raise "brotli compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
-    STDERR.puts `chmod +r #{path}.br`.strip
-    raise "chmod failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
-  end
+  STDERR.puts brotli_command(path)
+  STDERR.puts `#{brotli_command(path)}`
+  raise "brotli compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
+  STDERR.puts `chmod +r #{path}.br`.strip
+  raise "chmod failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
 end
 
 def compress(from, to)
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index cae84db..e16c874 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -5,7 +5,6 @@ describe ApplicationHelper do
   describe "preload_script" do
     it "provides brotli links to brotli cdn" do
       set_cdn_url "https://awesome.com"
-      set_env "COMPRESS_BROTLI", "1"
 
       helper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'
       link = helper.preload_script('application')
@@ -20,7 +19,6 @@ describe ApplicationHelper do
         global_setting :s3_access_key_id, '123'
         global_setting :s3_secret_access_key, '123'
         global_setting :s3_cdn_url, 'https://s3cdn.com'
-        set_env "COMPRESS_BROTLI", "1"
       end
 
       after do

GitHub sha: baa7a983

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Hmm this is running everytime on boot now.

We don’t need to support the old brotli anymore I will remove it