mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
also add file name to inline send_file
This commit is contained in:
parent
8d6b69c315
commit
461dafaf60
2 changed files with 14 additions and 8 deletions
|
@ -252,8 +252,8 @@ module Sinatra
|
|||
|
||||
# Set the Content-Disposition to "attachment" with the specified filename,
|
||||
# instructing the user agents to prompt to save.
|
||||
def attachment(filename=nil)
|
||||
response['Content-Disposition'] = 'attachment'
|
||||
def attachment(filename = nil, disposition = 'attachment')
|
||||
response['Content-Disposition'] = disposition.to_s
|
||||
if filename
|
||||
params = '; filename="%s"' % File.basename(filename)
|
||||
response['Content-Disposition'] << params
|
||||
|
@ -268,11 +268,11 @@ module Sinatra
|
|||
content_type opts[:type] || File.extname(path), :default => 'application/octet-stream'
|
||||
end
|
||||
|
||||
if opts[:disposition] == 'attachment' || opts[:filename]
|
||||
attachment opts[:filename] || path
|
||||
elsif opts[:disposition] == 'inline'
|
||||
response['Content-Disposition'] = 'inline'
|
||||
end
|
||||
disposition = opts[:disposition]
|
||||
filename = opts[:filename]
|
||||
disposition = 'attachment' if disposition.nil? and filename
|
||||
filename = path if filename.nil?
|
||||
attachment(filename, disposition) if disposition
|
||||
|
||||
last_modified opts[:last_modified] if opts[:last_modified]
|
||||
|
||||
|
|
|
@ -701,10 +701,16 @@ class HelpersTest < Test::Unit::TestCase
|
|||
assert_equal 'attachment; filename="file.txt"', response['Content-Disposition']
|
||||
end
|
||||
|
||||
it "does not set add a file name if filename is false" do
|
||||
send_file_app :disposition => 'inline', :filename => false
|
||||
get '/file.txt'
|
||||
assert_equal 'inline', response['Content-Disposition']
|
||||
end
|
||||
|
||||
it "sets the Content-Disposition header when :disposition set to 'inline'" do
|
||||
send_file_app :disposition => 'inline'
|
||||
get '/file.txt'
|
||||
assert_equal 'inline', response['Content-Disposition']
|
||||
assert_equal 'inline; filename="file.txt"', response['Content-Disposition']
|
||||
end
|
||||
|
||||
it "sets the Content-Disposition header when :filename provided" do
|
||||
|
|
Loading…
Reference in a new issue