Skip to content

Commit

Permalink
Always respect :type parameter for send_file. Fixes GH sinatra#42
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Sep 1, 2010
1 parent 108162b commit 0b032a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def send_file(path, opts={})
last_modified stat.mtime last_modified stat.mtime


content_type mime_type(opts[:type]) || content_type mime_type(opts[:type]) ||
opts[:type] ||
mime_type(File.extname(path)) || mime_type(File.extname(path)) ||
response['Content-Type'] || response['Content-Type'] ||
'application/octet-stream' 'application/octet-stream'
Expand Down
12 changes: 12 additions & 0 deletions test/helpers_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -345,6 +345,18 @@ def send_file_app(opts={})
assert_equal 'text/plain', response['Content-Type'] assert_equal 'text/plain', response['Content-Type']
end 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 it 'sets the Content-Length response header' do
send_file_app send_file_app
get '/file.txt' get '/file.txt'
Expand Down

0 comments on commit 0b032a0

Please sign in to comment.