Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

also add file name to inline send_file

  • Loading branch information...
commit 461dafaf6049597551ad261a3320f912785377be 1 parent 8d6b69c
@rkh rkh authored
Showing with 14 additions and 8 deletions.
  1. +7 −7 lib/sinatra/base.rb
  2. +7 −1 test/helpers_test.rb
View
14 lib/sinatra/base.rb
@@ -252,8 +252,8 @@ def content_type(type = nil, params={})
# 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 @@ def send_file(path, opts={})
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]
View
8 test/helpers_test.rb
@@ -701,10 +701,16 @@ def send_file_app(opts={})
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
Please sign in to comment.
Something went wrong with that request. Please try again.