set sinara.static_file env var when serving static files

This commit is contained in:
Ryan Tomayko 2010-01-28 08:59:30 -08:00
parent ae8ac8fdd6
commit 84b82a3712
2 changed files with 7 additions and 0 deletions

View File

@ -525,6 +525,7 @@ module Sinatra
return if path[0, public_dir.length] != public_dir
return unless File.file?(path)
env['sinatra.static_file'] = path
send_file path, :disposition => nil
end

View File

@ -26,6 +26,12 @@ class StaticTest < Test::Unit::TestCase
assert_equal File.read(__FILE__), buf1.join
end
it 'sets the sinatra.static_file env variable if served' do
env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
status, headers, body = @app.call(env)
assert_equal File.expand_path(__FILE__), env['sinatra.static_file']
end
it 'serves HEAD requests for files in the public directory' do
head "/#{File.basename(__FILE__)}"
assert ok?