Send a better content type than application/octet-stream (#19131).

git-svn-id: http://svn.redmine.org/redmine/trunk@14034 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-02-19 17:46:24 +00:00
parent d750c9906e
commit 0b04de0a23
4 changed files with 14 additions and 5 deletions

View File

@@ -183,7 +183,7 @@ class AttachmentsController < ApplicationController
def detect_content_type(attachment) def detect_content_type(attachment)
content_type = attachment.content_type 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) content_type = Redmine::MimeType.of(attachment.filename)
end end
content_type.to_s content_type.to_s

View File

@@ -78,7 +78,7 @@ attachments_006:
filesize: 157 filesize: 157
filename: archive.zip filename: archive.zip
author_id: 2 author_id: 2
content_type: application/octet-stream content_type: application/zip
attachments_007: attachments_007:
created_on: 2006-07-19 21:07:27 +02:00 created_on: 2006-07-19 21:07:27 +02:00
container_type: Issue container_type: Issue
@@ -91,7 +91,7 @@ attachments_007:
filesize: 157 filesize: 157
filename: archive.zip filename: archive.zip
author_id: 1 author_id: 1
content_type: application/octet-stream content_type: application/zip
attachments_008: attachments_008:
created_on: 2006-07-19 21:07:27 +02:00 created_on: 2006-07-19 21:07:27 +02:00
container_type: Project container_type: Project

View File

@@ -192,7 +192,7 @@ class AttachmentsControllerTest < ActionController::TestCase
def test_show_other def test_show_other
get :show, :id => 6 get :show, :id => 6
assert_response :success assert_response :success
assert_equal 'application/octet-stream', @response.content_type assert_equal 'application/zip', @response.content_type
set_tmp_attachments_directory set_tmp_attachments_directory
end end
@@ -262,6 +262,15 @@ class AttachmentsControllerTest < ActionController::TestCase
set_tmp_attachments_directory set_tmp_attachments_directory
end 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 def test_download_missing_file
get :download, :id => 2 get :download, :id => 2
assert_response 404 assert_response 404

View File

@@ -65,7 +65,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
test "GET /attachments/download/:id/:filename should return the attachment content" do test "GET /attachments/download/:id/:filename should return the attachment content" do
get '/attachments/download/7/archive.zip', {}, credentials('jsmith') get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
assert_response :success assert_response :success
assert_equal 'application/octet-stream', @response.content_type assert_equal 'application/zip', @response.content_type
set_tmp_attachments_directory set_tmp_attachments_directory
end end