diff options
author | Thomas Fuchs <thomas@fesch.at> | 2007-02-09 11:25:37 +0000 |
---|---|---|
committer | Thomas Fuchs <thomas@fesch.at> | 2007-02-09 11:25:37 +0000 |
commit | c9108f3e399ad2b81d7001489a4036d69333add5 (patch) | |
tree | 10e6a607880e4ea6b8c532638e9ae965941be64f /actionpack | |
parent | 9daddf0116f2e88153e4473bb9aa5b8edc186963 (diff) | |
download | rails-c9108f3e399ad2b81d7001489a4036d69333add5.tar.gz rails-c9108f3e399ad2b81d7001489a4036d69333add5.tar.bz2 rails-c9108f3e399ad2b81d7001489a4036d69333add5.zip |
Add a :url_based_filename => true option to ActionController::Streaming::send_file, which allows URL-based filenames. [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6142 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/streaming.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/send_file_test.rb | 8 |
3 files changed, 14 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index a470bb5fb7..5b2a50f05c 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add a :url_based_filename => true option to ActionController::Streaming::send_file, which allows URL-based filenames. [Thomas Fuchs] + * Fix that FormTagHelper#submit_tag using :disable_with should trigger the onsubmit handler of its form if available [DHH] * Fix #render_file so that TemplateError is called with the correct params and you don't get the WSOD. [Rick] diff --git a/actionpack/lib/action_controller/streaming.rb b/actionpack/lib/action_controller/streaming.rb index 484913c7df..f82d7cf397 100644 --- a/actionpack/lib/action_controller/streaming.rb +++ b/actionpack/lib/action_controller/streaming.rb @@ -29,6 +29,9 @@ module ActionController #:nodoc: # * <tt>:buffer_size</tt> - specifies size (in bytes) of the buffer used to stream the file. # Defaults to 4096. # * <tt>:status</tt> - specifies the status code to send with the response. Defaults to '200 OK'. + # * <tt>:url_based_filename</tt> - set to true if you want the browser guess the filename from + # the URL, which is necessary for i18n filenames on certain browsers + # (setting :filename overrides this option). # # The default Content-Type and Content-Disposition headers are # set to download arbitrary binary files in as many browsers as @@ -59,7 +62,7 @@ module ActionController #:nodoc: raise MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path) options[:length] ||= File.size(path) - options[:filename] ||= File.basename(path) + options[:filename] ||= File.basename(path) unless options[:url_based_filename] send_file_headers! options @performed_render = false diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index e7ebc91676..77f1c3614b 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -53,6 +53,14 @@ class SendFileTest < Test::Unit::TestCase assert_nothing_raised { response.body.call(response, output) } assert_equal file_data, output.string end + + def test_file_url_based_filename + @controller.options = { :url_based_filename => true } + response = nil + assert_nothing_raised { response = process('file') } + assert_not_nil response + assert_equal "attachment", response.headers["Content-Disposition"] + end def test_data response = nil |