Always respect :type parameter for send_file. Fixes GH #42

This commit is contained in:
Konstantin Haase 2010-09-01 11:47:10 +02:00
parent 108162b343
commit 0b032a0c3e
2 changed files with 13 additions and 0 deletions

View File

@ -158,6 +158,7 @@ module Sinatra
last_modified stat.mtime
content_type mime_type(opts[:type]) ||
opts[:type] ||
mime_type(File.extname(path)) ||
response['Content-Type'] ||
'application/octet-stream'

View File

@ -345,6 +345,18 @@ class HelpersTest < Test::Unit::TestCase
assert_equal 'text/plain', response['Content-Type']
end
it 'sets the Content-Type response header if type option is set to a file extesion' do
send_file_app :type => 'html'
get '/file.txt'
assert_equal 'text/html', response['Content-Type']
end
it 'sets the Content-Type response header if type option is set to a mime type' do
send_file_app :type => 'application/octet-stream'
get '/file.txt'
assert_equal 'application/octet-stream', response['Content-Type']
end
it 'sets the Content-Length response header' do
send_file_app
get '/file.txt'