8000 [HttpFoundation] Fixed BinaryFileResponse sending wrong Content-Lengt… · symfony/symfony@53f807a · GitHub
[go: up one dir, main page]

Skip to content

Commit 53f807a

Browse files
committed
[HttpFoundation] Fixed BinaryFileResponse sending wrong Content-Length header for files modified by stream wrappers/filters.
1 parent 6de4359 commit 53f807a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal
186186
*/
187187
public function prepare(Request $request)
188188
{
189-
$this->headers->set('Content-Length', $this->file->getSize());
189+
// Get the file size from a stream rather than from disk in case it is changed later by
190+
// stream wrappers or stream filters.
191+
$file = fopen($this->file->getPathname(), 'rb');
192+
$fstat = fstat($file);
193+
$this->headers->set('Content-Length', $fstat['size']);
194+
fclose($file);
190195

191196
if (!$this->headers->has('Accept-Ranges')) {
192197
// Only accept ranges on safe HTTP methods

0 commit comments

Comments
 (0)
0