From 94156e5326fbd2d6d8e239c69b98071c4655fadc Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Adam=20Cig=C3=A1nek?= Date: Fri, 17 Oct 2008 22:32:05 +0200 Subject: [PATCH] allows use of symbols registered through Mime::Type.register for :type option of ActionController::Streaming#send_file/#send_data --- actionpack/lib/action_controller/streaming.rb | 6 +++++- actionpack/test/controller/send_file_test.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/streaming.rb b/actionpack/lib/action_controller/streaming.rb index 333fb61..96ff92f 100644 --- a/actionpack/lib/action_controller/streaming.rb +++ b/actionpack/lib/action_controller/streaming.rb @@ -143,9 +143,13 @@ module ActionController #:nodoc: disposition <<= %(; filename="#{options[:filename]}") if options[:filename] + content_type = options[:type] + content_type = Mime::Type.lookup_by_extension(content_type.to_s) if content_type.is_a?(Symbol) + content_type = content_type.to_s.strip # fixes a problem with extra '\r' with some browsers + headers.update( 'Content-Length' => options[:length], - 'Content-Type' => options[:type].to_s.strip, # fixes a problem with extra '\r' with some browsers + 'Content-Type' => content_type, 'Content-Disposition' => disposition, 'Content-Transfer-Encoding' => 'binary' ) diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index c003abf..15ce6f2 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -118,6 +118,20 @@ class SendFileTest < Test::Unit::TestCase assert_equal 'private', h['Cache-Control'] end + def test_send_file_headers_with_mime_lookup_with_symbol + options = { + :length => 1, + :type => :png + } + + @controller.headers = {} + @controller.send(:send_file_headers!, options) + + headers = @controller.headers + + assert_equal 'image/png', headers['Content-Type'] + end + %w(file data).each do |method| define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } -- 1.6.0.2