Return different headers for fingerprinted files
This commit is contained in:
parent
3b46bb1c10
commit
133be31e86
|
@ -82,19 +82,30 @@ class Travis::Web::App
|
||||||
|
|
||||||
def response_for(file, options = {})
|
def response_for(file, options = {})
|
||||||
content = File.read(file)
|
content = File.read(file)
|
||||||
set_config(content, options) if config_needed?(file)
|
if fingerprinted?(file)
|
||||||
set_title(content) if index?(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_title(content) if index?(file)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Content-Length' => content.bytesize.to_s,
|
||||||
|
'Cache-Control' => cache_control(file),
|
||||||
|
'Content-Location' => path_for(file),
|
||||||
|
'Content-Type' => mime_type(file),
|
||||||
|
'ETag' => %Q{"#{version}"},
|
||||||
|
'Last-Modified' => server_start.httpdate,
|
||||||
|
'Expires' => (server_start + age).httpdate,
|
||||||
|
'Vary' => vary_for(file)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
headers = {
|
|
||||||
'Content-Length' => content.bytesize.to_s,
|
|
||||||
'Cache-Control' => cache_control(file),
|
|
||||||
'Content-Location' => path_for(file),
|
|
||||||
'Content-Type' => mime_type(file),
|
|
||||||
'ETag' => %Q{"#{version}"},
|
|
||||||
'Last-Modified' => server_start.httpdate,
|
|
||||||
'Expires' => (server_start + age).httpdate,
|
|
||||||
'Vary' => vary_for(file)
|
|
||||||
}
|
|
||||||
[ 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"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user