In send_file: Do not override Content-Type if already set and no explicit type
is given. Fixes #130.
This commit is contained in:
parent
b30d664ea6
commit
88d378ab94
|
@ -166,8 +166,9 @@ module Sinatra
|
|||
stat = File.stat(path)
|
||||
last_modified stat.mtime
|
||||
|
||||
content_type opts[:type] || File.extname(path),
|
||||
:default => response['Content-Type'] || 'application/octet-stream'
|
||||
if opts[:type] or not response['Content-Type']
|
||||
content_type opts[:type] || File.extname(path), :default => 'application/octet-stream'
|
||||
end
|
||||
|
||||
if opts[:disposition] == 'attachment' || opts[:filename]
|
||||
attachment opts[:filename] || path
|
||||
|
|
|
@ -454,6 +454,30 @@ class HelpersTest < Test::Unit::TestCase
|
|||
get '/file.txt'
|
||||
assert_equal 'application/octet-stream', response['Content-Type']
|
||||
end
|
||||
|
||||
it "does not override Content-Type if already set and no explicit type is given" do
|
||||
path = @file
|
||||
mock_app do
|
||||
get '/' do
|
||||
content_type :png
|
||||
send_file path
|
||||
end
|
||||
end
|
||||
get '/'
|
||||
assert_equal 'image/png', response['Content-Type']
|
||||
end
|
||||
|
||||
it "does override Content-Type even if already set, if explicit type is given" do
|
||||
path = @file
|
||||
mock_app do
|
||||
get '/' do
|
||||
content_type :png
|
||||
send_file path, :type => :gif
|
||||
end
|
||||
end
|
||||
get '/'
|
||||
assert_equal 'image/gif', response['Content-Type']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cache_control' do
|
||||
|
|
Loading…
Reference in New Issue