]> source.dussan.org Git - redmine.git/commitdiff
Send a better content type than application/octet-stream (#19131).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 19 Feb 2015 17:46:24 +0000 (17:46 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 19 Feb 2015 17:46:24 +0000 (17:46 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14034 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
test/fixtures/attachments.yml
test/functional/attachments_controller_test.rb
test/integration/api_test/attachments_test.rb

index 4edcc0a41ed547730011fce9f1c897a390bfb731..9d3f7d75c564e1976aef25d0c87219e9567f32fa 100644 (file)
@@ -183,7 +183,7 @@ class AttachmentsController < ApplicationController
 
   def detect_content_type(attachment)
     content_type = attachment.content_type
-    if content_type.blank?
+    if content_type.blank? || content_type == "application/octet-stream"
       content_type = Redmine::MimeType.of(attachment.filename)
     end
     content_type.to_s
index 9437ed1024a55f51187e95640387433627184489..6f56c08119de8834b9fe48da92a5ffc5aea22908 100644 (file)
@@ -78,7 +78,7 @@ attachments_006:
   filesize: 157
   filename: archive.zip
   author_id: 2
-  content_type: application/octet-stream
+  content_type: application/zip
 attachments_007: 
   created_on: 2006-07-19 21:07:27 +02:00
   container_type: Issue
@@ -91,7 +91,7 @@ attachments_007:
   filesize: 157
   filename: archive.zip
   author_id: 1
-  content_type: application/octet-stream
+  content_type: application/zip
 attachments_008: 
   created_on: 2006-07-19 21:07:27 +02:00
   container_type: Project
index efd537599074213534dec4c6a801b3973888da47..5174c8da1a04ff8c044cc4476b5e130624d3c7f0 100644 (file)
@@ -192,7 +192,7 @@ class AttachmentsControllerTest < ActionController::TestCase
   def test_show_other
     get :show, :id => 6
     assert_response :success
-    assert_equal 'application/octet-stream', @response.content_type
+    assert_equal 'application/zip', @response.content_type
     set_tmp_attachments_directory
   end
 
@@ -262,6 +262,15 @@ class AttachmentsControllerTest < ActionController::TestCase
     set_tmp_attachments_directory
   end
 
+  def test_download_should_assign_better_content_type_than_application_octet_stream
+    Attachment.find(4).update! :content_type => "application/octet-stream"
+
+    get :download, :id => 4
+    assert_response :success
+    assert_equal 'text/x-ruby', @response.content_type
+    set_tmp_attachments_directory
+  end
+
   def test_download_missing_file
     get :download, :id => 2
     assert_response 404
index d4b4835271a69a0ad1210c3ea40eec7607c5bbc2..0f7e6ebdb7f67114865327bcc1b71e104e7208e9 100644 (file)
@@ -65,7 +65,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
   test "GET /attachments/download/:id/:filename should return the attachment content" do
     get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
     assert_response :success
-    assert_equal 'application/octet-stream', @response.content_type
+    assert_equal 'application/zip', @response.content_type
     set_tmp_attachments_directory
   end