From 54329d836c0a63fec3f2b10f8c222cb865187f9d Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 9 Mar 2016 16:57:57 +0000 Subject: [PATCH] [HttpFoundation] Set the Content-Range header if the requested Range is unsatisfied --- src/Symfony/Component/HttpFoundation/BinaryFileResponse.php | 1 + .../Component/HttpFoundation/Tests/BinaryFileResponseTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 490726dadf799..8e2e0f4bb56d6 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -252,6 +252,7 @@ public function prepare(Request $request) if ($start <= $end) { if ($start < 0 || $end > $fileSize - 1) { $this->setStatusCode(416); + $this->headers->set('Content-Range', sprintf('bytes */%s', $fileSize)); } elseif ($start !== 0 || $end !== $fileSize - 1) { $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1; $this->offset = $start; diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index 4c055ff8a17f8..8f6b0e7424c91 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -211,7 +211,7 @@ public function testInvalidRequests($requestRange) $response->sendContent(); $this->assertEquals(416, $response->getStatusCode()); - #$this->assertEquals('', $response->headers->get('Content-Range')); + $this->assertEquals('bytes */35', $response->headers->get('Content-Range')); } public function provideInvalidRanges()