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
This commit is contained in:
Sam Saffron 2019-04-11 12:36:02 +10:00
parent 7a7c6af21e
commit baa7a9836c
3 changed files with 18 additions and 25 deletions

View File

@ -54,7 +54,6 @@ module ApplicationHelper
end
def is_brotli_req?
ENV["COMPRESS_BROTLI"] == "1" &&
request.env["HTTP_ACCEPT_ENCODING"] =~ /br/
end

View File

@ -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)

View File

@ -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