From baa7a9836cf547b1ae9eefa51096718706c00602 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 11 Apr 2019 12:36:02 +1000 Subject: [PATCH] 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 --- app/helpers/application_helper.rb | 1 - lib/tasks/assets.rake | 40 +++++++++++-------------- spec/helpers/application_helper_spec.rb | 2 -- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0f9c896da70..69d1979c0d3 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 c389ea2f044..03ca08924da 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 cae84db2f4c..e16c87499ce 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