Permalink
Browse files

set sinara.static_file env var when serving static files

  • Loading branch information...
1 parent ae8ac8f commit 84b82a3712443ae8539baaa4f55921f00cfba6e1 @rtomayko rtomayko committed Jan 28, 2010
Showing with 7 additions and 0 deletions.
  1. +1 −0 lib/sinatra/base.rb
  2. +6 −0 test/static_test.rb
View
@@ -525,6 +525,7 @@ def static!
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
@@ -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?

0 comments on commit 84b82a3

Please sign in to comment.