Add specs for PublicFileServer middleware (#35219)

This commit is contained in:
Claire 2025-06-30 13:23:11 +02:00 committed by GitHub
commit 153af19f55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 62 additions and 6 deletions

View file

@ -22,12 +22,11 @@ module Mastodon
status, headers, response = file
# Set cache headers on static files. Some paths require different cache headers
request = Rack::Request.new env
headers['cache-control'] = begin
request_path = env['REQUEST_PATH']
if request_path.start_with?('/sw.js')
if request.path.start_with?('/sw.js')
"public, max-age=#{SERVICE_WORKER_TTL}, must-revalidate"
elsif request_path.start_with?(paperclip_root_url)
elsif request.path.start_with?(paperclip_root_url)
"public, max-age=#{CACHE_TTL}, immutable"
else
"public, max-age=#{CACHE_TTL}, must-revalidate"
@ -35,9 +34,9 @@ module Mastodon
end
# Override the default CSP header set by the CSP middleware
headers['Content-Security-Policy'] = "default-src 'none'; form-action 'none'" if request_path.start_with?(paperclip_root_url)
headers['content-security-policy'] = "default-src 'none'; form-action 'none'" if request.path.start_with?(paperclip_root_url)
headers['X-Content-Type-Options'] = 'nosniff'
headers['x-content-type-options'] = 'nosniff'
[status, headers, response]
end