##// END OF EJS Templates
Send a better content type than application/octet-stream (#19131)....
Jean-Philippe Lang -
r13652:0b04de0a23e2
parent child
Show More
@@ -183,7 +183,7 class AttachmentsController < ApplicationController
183
183
184 def detect_content_type(attachment)
184 def detect_content_type(attachment)
185 content_type = attachment.content_type
185 content_type = attachment.content_type
186 if content_type.blank?
186 if content_type.blank? || content_type == "application/octet-stream"
187 content_type = Redmine::MimeType.of(attachment.filename)
187 content_type = Redmine::MimeType.of(attachment.filename)
188 end
188 end
189 content_type.to_s
189 content_type.to_s
@@ -78,7 +78,7 attachments_006:
78 filesize: 157
78 filesize: 157
79 filename: archive.zip
79 filename: archive.zip
80 author_id: 2
80 author_id: 2
81 content_type: application/octet-stream
81 content_type: application/zip
82 attachments_007:
82 attachments_007:
83 created_on: 2006-07-19 21:07:27 +02:00
83 created_on: 2006-07-19 21:07:27 +02:00
84 container_type: Issue
84 container_type: Issue
@@ -91,7 +91,7 attachments_007:
91 filesize: 157
91 filesize: 157
92 filename: archive.zip
92 filename: archive.zip
93 author_id: 1
93 author_id: 1
94 content_type: application/octet-stream
94 content_type: application/zip
95 attachments_008:
95 attachments_008:
96 created_on: 2006-07-19 21:07:27 +02:00
96 created_on: 2006-07-19 21:07:27 +02:00
97 container_type: Project
97 container_type: Project
@@ -192,7 +192,7 class AttachmentsControllerTest < ActionController::TestCase
192 def test_show_other
192 def test_show_other
193 get :show, :id => 6
193 get :show, :id => 6
194 assert_response :success
194 assert_response :success
195 assert_equal 'application/octet-stream', @response.content_type
195 assert_equal 'application/zip', @response.content_type
196 set_tmp_attachments_directory
196 set_tmp_attachments_directory
197 end
197 end
198
198
@@ -262,6 +262,15 class AttachmentsControllerTest < ActionController::TestCase
262 set_tmp_attachments_directory
262 set_tmp_attachments_directory
263 end
263 end
264
264
265 def test_download_should_assign_better_content_type_than_application_octet_stream
266 Attachment.find(4).update! :content_type => "application/octet-stream"
267
268 get :download, :id => 4
269 assert_response :success
270 assert_equal 'text/x-ruby', @response.content_type
271 set_tmp_attachments_directory
272 end
273
265 def test_download_missing_file
274 def test_download_missing_file
266 get :download, :id => 2
275 get :download, :id => 2
267 assert_response 404
276 assert_response 404
@@ -65,7 +65,7 class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
65 test "GET /attachments/download/:id/:filename should return the attachment content" do
65 test "GET /attachments/download/:id/:filename should return the attachment content" do
66 get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
66 get '/attachments/download/7/archive.zip', {}, credentials('jsmith')
67 assert_response :success
67 assert_response :success
68 assert_equal 'application/octet-stream', @response.content_type
68 assert_equal 'application/zip', @response.content_type
69 set_tmp_attachments_directory
69 set_tmp_attachments_directory
70 end
70 end
71
71
General Comments 0
You need to be logged in to leave comments. Login now