FEATURE: brotli cdn bypass for assets

Allow CDNS that strip out brotli encoding to use brotli regardless
This commit is contained in:
Sam
2016-12-05 13:57:09 +11:00
parent bd217bb440
commit 39a524aac8
5 changed files with 53 additions and 6 deletions

View File

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