diff options
| -rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
| -rwxr-xr-x | actionpack/lib/action_controller/base.rb | 8 | ||||
| -rw-r--r-- | actionpack/test/controller/send_file_test.rb | 24 |
3 files changed, 30 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index f1a24dc3fa..2cd5abeda8 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that send_file would "remember" all the files sent by adding to the headers again and again #458 [bitsweat] + * Fixed url rewriter confusion when the controller or action name was a substring of the controller_prefix or action_prefix * Added conditional layouts like <tt>layout "weblog_standard", :except => :rss</tt> #452 [Marcel Molina] diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 33e3014ee9..64dc79a24a 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -178,11 +178,11 @@ module ActionController #:nodoc: DEFAULT_RENDER_STATUS_CODE = "200 OK" DEFAULT_SEND_FILE_OPTIONS = { - :type => 'application/octet_stream', - :disposition => 'attachment', + :type => 'application/octet_stream'.freeze, + :disposition => 'attachment'.freeze, :stream => true, :buffer_size => 4096 - } + }.freeze # Determines whether the view has access to controller internals @request, @response, @session, and @template. # By default, it does. @@ -664,7 +664,7 @@ module ActionController #:nodoc: raise ArgumentError, ":#{arg} option required" if options[arg].nil? end - disposition = options[:disposition] || 'attachment' + disposition = options[:disposition].dup || 'attachment' disposition <<= %(; filename="#{options[:filename]}") if options[:filename] @headers.update( diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 57205a01c5..d18d15b18a 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -65,4 +65,28 @@ class SendFileTest < Test::Unit::TestCase assert_kind_of String, response.body assert_equal file_data, response.body end + + # Test that send_file_headers! is setting the correct HTTP headers. + def test_send_file_headers! + options = { + :length => 1, + :type => 'type', + :disposition => 'disposition', + :filename => 'filename' + } + + # Do it a few times: the resulting headers should be identical + # no matter how many times you send with the same options. + # Test resolving Ticket #458. + @controller.headers = {} + @controller.send(:send_file_headers!, options) + @controller.send(:send_file_headers!, options) + @controller.send(:send_file_headers!, options) + + h = @controller.headers + assert_equal 1, h['Content-Length'] + assert_equal 'type', h['Content-Type'] + assert_equal 'disposition; filename="filename"', h['Content-Disposition'] + assert_equal 'binary', h['Content-Transfer-Encoding'] + end end |
