Return different headers for fingerprinted files

This commit is contained in:
Piotr Sarnacki 2015-01-16 12:17:10 +01:00
parent 3b46bb1c10
commit 133be31e86

View File

@ -82,6 +82,15 @@ class Travis::Web::App
def response_for(file, options = {}) def response_for(file, options = {})
content = File.read(file) content = File.read(file)
if fingerprinted?(file)
headers = {
'Content-Length' => content.bytesize.to_s,
'Cache-Control' => cache_control(file),
'Content-Location' => path_for(file),
'Content-Type' => mime_type(file),
'Expires' => (server_start + age).httpdate,
}
else
set_config(content, options) if config_needed?(file) set_config(content, options) if config_needed?(file)
set_title(content) if index?(file) set_title(content) if index?(file)
@ -95,6 +104,8 @@ class Travis::Web::App
'Expires' => (server_start + age).httpdate, 'Expires' => (server_start + age).httpdate,
'Vary' => vary_for(file) 'Vary' => vary_for(file)
} }
end
[ 200, headers, [content] ] [ 200, headers, [content] ]
end end
@ -110,6 +121,11 @@ class Travis::Web::App
file.end_with?('index.html') file.end_with?('index.html')
end end
def fingerprinted?(file)
basename = File.basename(file)
basename =~ /-[a-f0-9]{32}.(css|js)$/
end
def cache_control(file) def cache_control(file)
case path_for(file) case path_for(file)
when '/' then "public, must-revalidate" when '/' then "public, must-revalidate"