Set Content-Type to fixed value for all download actions

This commit is contained in:
Sebastian Serth
2022-10-05 21:46:17 +02:00
parent 42688ed1c9
commit f7515362a1
4 changed files with 5 additions and 5 deletions

View File

@ -23,7 +23,7 @@ module CodeOcean
raise Pundit::NotAuthorizedError if @embed_options[:disable_download] || @file.filepath != params[:filename] raise Pundit::NotAuthorizedError if @embed_options[:disable_download] || @file.filepath != params[:filename]
real_location = Pathname(@file.native_file.current_path).realpath real_location = Pathname(@file.native_file.current_path).realpath
send_file(real_location, type: @file.native_file.content_type, filename: @file.name_with_extension, disposition: 'attachment') send_file(real_location, type: 'application/octet-stream', filename: @file.name_with_extension, disposition: 'attachment')
end end
def render_protected_upload def render_protected_upload

View File

@ -57,7 +57,7 @@ class SubmissionsController < ApplicationController
end end
zip_data = stringio.string zip_data = stringio.string
response.set_header('Content-Length', zip_data.size) response.set_header('Content-Length', zip_data.size)
send_data(zip_data, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip") send_data(zip_data, type: 'application/octet-stream', filename: "#{@submission.exercise.title.tr(' ', '_')}.zip", disposition: 'attachment')
end end
def download_file def download_file
@ -67,7 +67,7 @@ class SubmissionsController < ApplicationController
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath) redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
else else
response.set_header('Content-Length', @file.size) response.set_header('Content-Length', @file.size)
send_data(@file.content, filename: @file.name_with_extension, disposition: 'attachment') send_data(@file.content, type: 'application/octet-stream', filename: @file.name_with_extension, disposition: 'attachment')
end end
end end

View File

@ -17,7 +17,7 @@ describe CodeOcean::FilesController do
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } } let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
expect_assigns(file: :file) expect_assigns(file: :file)
expect_content_type('video/mp4') expect_content_type('application/octet-stream')
expect_http_status(:ok) expect_http_status(:ok)
it 'sets the correct filename' do it 'sets the correct filename' do

View File

@ -85,7 +85,7 @@ describe SubmissionsController do
expect_assigns(file: :file) expect_assigns(file: :file)
expect_assigns(submission: :submission) expect_assigns(submission: :submission)
expect_content_type('text/javascript') expect_content_type('application/octet-stream')
expect_http_status(:ok) expect_http_status(:ok)
it 'sets the correct filename' do it 'sets the correct filename' do