mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
If file extension is unknown, send_file will always fall back to application/octet-stream rather than complaining. Fixes #127.
This commit is contained in:
parent
45f954fa32
commit
6d3d45df10
2 changed files with 12 additions and 5 deletions
|
@ -140,7 +140,8 @@ module Sinatra
|
|||
# Set the Content-Type of the response body given a media type or file
|
||||
# extension.
|
||||
def content_type(type, params={})
|
||||
mime_type = mime_type(type)
|
||||
default = params.delete :default
|
||||
mime_type = mime_type(type) || default
|
||||
fail "Unknown media type: %p" % type if mime_type.nil?
|
||||
mime_type = mime_type.dup
|
||||
unless params.include? :charset or settings.add_charset.all? { |p| not p === mime_type }
|
||||
|
@ -165,10 +166,8 @@ module Sinatra
|
|||
stat = File.stat(path)
|
||||
last_modified stat.mtime
|
||||
|
||||
content_type opts[:type] ||
|
||||
File.extname(path) ||
|
||||
response['Content-Type'] ||
|
||||
'application/octet-stream'
|
||||
content_type opts[:type] || File.extname(path),
|
||||
:default => response['Content-Type'] || 'application/octet-stream'
|
||||
|
||||
if opts[:disposition] == 'attachment' || opts[:filename]
|
||||
attachment opts[:filename] || path
|
||||
|
|
|
@ -446,6 +446,14 @@ class HelpersTest < Test::Unit::TestCase
|
|||
get '/file.txt'
|
||||
assert_equal 'attachment; filename="foo.txt"', response['Content-Disposition']
|
||||
end
|
||||
|
||||
it "is able to send files with unkown mime type" do
|
||||
@file = File.dirname(__FILE__) + '/file.foobar'
|
||||
File.open(@file, 'wb') { |io| io.write('Hello World') }
|
||||
send_file_app
|
||||
get '/file.txt'
|
||||
assert_equal 'application/octet-stream', response['Content-Type']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'cache_control' do
|
||||
|
|
Loading…
Add table
Reference in a new issue