From c410fdc82f747c24555c0e9f39f942720c0e6204 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 8 Nov 2023 22:36:32 +0100 Subject: [PATCH] Make sure that content-length header can never be deleted Once the response is `commit`ted, the headers can't be edited anymore, which is exactly what we want in this case. --- app/controllers/tracks_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index a54184b3..945ee087 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -116,6 +116,10 @@ def audio_with_stream(stream, mimetype, total_size) response.content_type = mimetype response.headers['accept-ranges'] = 'bytes' response.headers['content-length'] = (last_byte - first_byte + 1).to_s + # Unfortunately, if we don't commit the headers, ActionController::Live will + # delete the "content-length" header set above. No other headers need to be + # set, so we just freeze them here. + response.commit! to_skip = first_byte while to_skip.positive?