Project

General

Profile

Feature #43484 » 0006-Send-an-attachment-inline-based-on-its-detected-cont.patch

Go MAEDA, 2026-08-05 12:10

View differences:

app/controllers/attachments_controller.rb
end
if stale?(:etag => @attachment.digest, :template => false)
# images are sent inline
# PDFs are sent inline
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
:type => detect_content_type(@attachment),
:disposition => disposition(@attachment)
......
end
def disposition(attachment)
if attachment.is_pdf?
if detect_content_type(attachment) == 'application/pdf'
'inline'
else
'attachment'
test/functional/attachments_controller_test.rb
assert_equal 'text/javascript', @response.media_type
end
def test_download_should_not_send_a_non_pdf_file_inline_even_with_a_pdf_extension
set_tmp_attachments_directory
attachment = Attachment.create!(
:file => mock_file_with_options(:original_filename => 'fake.pdf',
:content => '<html><body>Hello</body></html>'),
:author_id => 2,
:container => Issue.find(1)
)
get(:download, :params => {:id => attachment.id})
assert_response :success
assert_equal 'text/html', @response.media_type
assert_match %r{\Aattachment}, @response.headers['Content-Disposition']
end
def test_download_version_file_with_issue_tracking_disabled
Project.find(1).disable_module! :issue_tracking
get(:download, :params => {:id => 9})
(10-10/10)