Browse files

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

  • Loading branch information...
1 parent 108162b commit 0b032a0c3ecb8855e080a0e4d1d904a7271090a4 @rkh committed Sep 1, 2010
Showing with 13 additions and 0 deletions.
  1. +1 −0 lib/sinatra/base.rb
  2. +12 −0 test/helpers_test.rb
View
1 lib/sinatra/base.rb
@@ -158,6 +158,7 @@ def send_file(path, opts={})
last_modified stat.mtime
content_type mime_type(opts[:type]) ||
+ opts[:type] ||
mime_type(File.extname(path)) ||
response['Content-Type'] ||
'application/octet-stream'
View
12 test/helpers_test.rb
@@ -345,6 +345,18 @@ def send_file_app(opts={})
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'

0 comments on commit 0b032a0

Please sign in to comment.