adds check for :static_cache_control setting to Sinatra::Base.static!
This commit is contained in:
parent
89c6a38a15
commit
9dc155f3e9
|
@ -708,6 +708,7 @@ module Sinatra
|
|||
return unless path.start_with?(public_dir) and File.file?(path)
|
||||
|
||||
env['sinatra.static_file'] = path
|
||||
cache_control *settings.static_cache_control if settings.static_cache_control?
|
||||
send_file path, :disposition => nil
|
||||
end
|
||||
|
||||
|
@ -1339,6 +1340,7 @@ module Sinatra
|
|||
|
||||
set :public, Proc.new { root && File.join(root, 'public') }
|
||||
set :static, Proc.new { public && File.exist?(public) }
|
||||
set :static_cache_control, false
|
||||
|
||||
error ::Exception do
|
||||
response.status = 500
|
||||
|
|
|
@ -154,4 +154,25 @@ class StaticTest < Test::Unit::TestCase
|
|||
assert_equal "bytes */#{length}",response['Content-Range'], "416 response should include actual length"
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not include static cache control headers by default' do
|
||||
env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
|
||||
status, headers, body = @app.call(env)
|
||||
assert !headers.has_key?('Cache-Control')
|
||||
end
|
||||
|
||||
it 'sets cache control headers on static files if set' do
|
||||
@app.set :static_cache_control, :public
|
||||
env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
|
||||
status, headers, body = @app.call(env)
|
||||
assert headers.has_key?('Cache-Control')
|
||||
assert_equal headers['Cache-Control'], 'public'
|
||||
|
||||
@app.set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
|
||||
env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
|
||||
status, headers, body = @app.call(env)
|
||||
assert headers.has_key?('Cache-Control')
|
||||
assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue