#send_file indifferent :status option

This commit is contained in:
George 2013-09-25 05:07:10 +04:00
parent 65a00a2033
commit 29a62dc7a2
2 changed files with 12 additions and 0 deletions

View File

@ -366,6 +366,7 @@ module Sinatra
result = file.serving env result = file.serving env
result[1].each { |k,v| headers[k] ||= v } result[1].each { |k,v| headers[k] ||= v }
headers['Content-Length'] = result[1]['Content-Length'] headers['Content-Length'] = result[1]['Content-Length']
opts[:status] = opts[:status].to_i if opts[:status].is_a?(String)
halt opts[:status] || result[0], result[2] halt opts[:status] || result[0], result[2]
rescue Errno::ENOENT rescue Errno::ENOENT
not_found not_found

View File

@ -905,6 +905,17 @@ class HelpersTest < Test::Unit::TestCase
get '/' get '/'
assert_equal 'image/gif', response['Content-Type'] assert_equal 'image/gif', response['Content-Type']
end end
it 'can have :status option as a string' do
path = @file
mock_app do
post '/' do
send_file path, :status => '422'
end
end
post '/'
assert_equal response.status, 422
end
end end
describe 'cache_control' do describe 'cache_control' do