Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix open/save dialog in IE not opening files send with send_file/send…

…_data, #2279

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2325 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 2346f5716f7b08168b74b29e0279d51c51557b08 1 parent 2a35baa
@madrobby madrobby authored
View
11 actionpack/lib/action_controller/streaming.rb
@@ -120,6 +120,7 @@ def send_file_headers!(options)
end
disposition = options[:disposition].dup || 'attachment'
+
disposition <<= %(; filename="#{options[:filename]}") if options[:filename]
@headers.update(
@@ -127,7 +128,15 @@ def send_file_headers!(options)
'Content-Type' => options[:type].strip, # fixes a problem with extra '\r' with some browsers
'Content-Disposition' => disposition,
'Content-Transfer-Encoding' => 'binary'
- );
+ )
+
+ # Fix a problem with IE 6.0 on opening downloaded files:
+ # If Cache-Control: no-cache is set (which Rails does by default),
+ # IE removes the file it just downloaded from its cache immediately
+ # after it displays the "open/save" dialog, which means that if you
+ # hit "open" the file isn't there anymore when the application that
+ # is called for handling the download is run, so let's workaround that
+ @headers['Cache-Control'] = 'private' if @headers['Cache-Control'] == 'no-cache'
end
end
end
View
6 actionpack/test/controller/send_file_test.rb
@@ -85,5 +85,11 @@ def test_send_file_headers!
assert_equal 'type', h['Content-Type']
assert_equal 'disposition; filename="filename"', h['Content-Disposition']
assert_equal 'binary', h['Content-Transfer-Encoding']
+
+ # test overriding Cache-Control: no-cache header to fix IE open/save dialog
+ @controller.headers = { 'Cache-Control' => 'no-cache' }
+ @controller.send(:send_file_headers!, options)
+ h = @controller.headers
+ assert_equal 'private', h['Cache-Control']
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.