mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 08:16:00 +08:00
FEATURE: brotli cdn bypass for assets
Allow CDNS that strip out brotli encoding to use brotli regardless
This commit is contained in:
@ -11,6 +11,7 @@ module Middleware
|
||||
class Helper
|
||||
USER_AGENT = "HTTP_USER_AGENT".freeze
|
||||
RACK_SESSION = "rack.session".freeze
|
||||
ACCEPT_ENCODING = "HTTP_ACCEPT_ENCODING".freeze
|
||||
|
||||
def initialize(env)
|
||||
@env = env
|
||||
@ -35,6 +36,14 @@ module Middleware
|
||||
@is_mobile == :true
|
||||
end
|
||||
|
||||
def has_brotli?
|
||||
@has_brotli ||=
|
||||
begin
|
||||
@env[ACCEPT_ENCODING].to_s =~ /br/ ? :true : :false
|
||||
end
|
||||
@has_brotli == :true
|
||||
end
|
||||
|
||||
def is_crawler?
|
||||
@is_crawler ||=
|
||||
begin
|
||||
@ -45,7 +54,7 @@ module Middleware
|
||||
end
|
||||
|
||||
def cache_key
|
||||
@cache_key ||= "ANON_CACHE_#{@env["HTTP_ACCEPT"]}_#{@env["HTTP_HOST"]}#{@env["REQUEST_URI"]}|m=#{is_mobile?}|c=#{is_crawler?}"
|
||||
@cache_key ||= "ANON_CACHE_#{@env["HTTP_ACCEPT"]}_#{@env["HTTP_HOST"]}#{@env["REQUEST_URI"]}|m=#{is_mobile?}|c=#{is_crawler?}|b=#{has_brotli?}"
|
||||
end
|
||||
|
||||
def cache_key_body
|
||||
|
Reference in New Issue
Block a user