Description
Symfony version(s) affected
6.4.x
Description
BinaryFileResponse returns Status 200 and no Content-Length or Content-Range headers when sending a request with "Range: bytes=0-".
I have a controller that sends large mp3 files for an html audio player. The audio file is loaded and starts playing in all browsers, but only Firefox allows seeking. Chrome and Edge just restart the audio when trying to seek.
I narroewed the issue to line 263 in BinaryFileResponse.php
} elseif ($end - $start < $fileSize - 1) {
Because $end is set to $fileSize -1 if not present in the Range header, the above condition will never be met.
Changing the above line to:
} elseif ($end - $start <= $fileSize - 1) {
Corrects the behaviour and the response from BinaryFileResponse is the same as from requesting a static file.
How to reproduce
Make a request from a web player for a large media file served by BinaryFileResponse. The server wil respond with Status 200 instead of Status 206 and proper headers.
Possible Solution
BinaryFileResponse.php (line 263):
} elseif ($end - $start <= $fileSize - 1) {
Additional Context
No response