From de024d936033140385d177adf069c168f3021aa0 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 4 Nov 2022 16:52:49 +0100 Subject: [PATCH] Set Content-Type to fixed value for send_runner_file --- app/controllers/live_streams_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/live_streams_controller.rb b/app/controllers/live_streams_controller.rb index 272b5698..f59771df 100644 --- a/app/controllers/live_streams_controller.rb +++ b/app/controllers/live_streams_controller.rb @@ -34,14 +34,15 @@ class LiveStreamsController < ApplicationController def send_runner_file(runner, desired_file, redirect_fallback = root_path, privileged: false) filename = File.basename(desired_file) - send_stream(filename: filename, disposition: 'attachment') do |stream| - runner.download_file desired_file, privileged_execution: privileged do |chunk, overall_size, content_type| + send_stream(filename: filename, type: 'application/octet-stream', disposition: 'attachment') do |stream| + runner.download_file desired_file, privileged_execution: privileged do |chunk, overall_size, _content_type| unless response.committed? # Disable Rack::ETag, which would otherwise cause the response to be cached # See https://github.com/rack/rack/issues/1619#issuecomment-848460528 response.set_header('Last-Modified', Time.now.httpdate) response.set_header('Content-Length', overall_size) if overall_size - response.set_header('Content-Type', content_type) if content_type + # We set the content type to 'application/octet-stream' in send_stream + # response.set_header('Content-Type', content_type) if content_type # Commit the response headers immediately, as streaming would otherwise remove the Content-Length header # This will prevent chunked transfer encoding from being used, which is okay as we know the overall size # See https://github.com/rails/rails/issues/18714