From d9b91458f1cd61073eb4478fe18173fe33e68e3c Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Sat, 9 Feb 2013 16:02:08 +0100 Subject: [PATCH] [HttpFoundation] Fixed byte ranges in the BinaryFileResponse. According to rfc2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.1) byte positions are inclusive: The first-byte-pos value in a byte-range-spec gives the byte-offset of the first byte in a range. The last-byte-pos value gives the byte-offset of the last byte in the range; that is, the byte positions specified are inclusive. Byte offsets start at zero. --- src/Symfony/Component/HttpFoundation/BinaryFileResponse.php | 2 +- .../Component/HttpFoundation/Tests/BinaryFileResponseTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index a5c77f0ab7..5c2bf48877 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -199,7 +199,7 @@ class BinaryFileResponse extends Response list($start, $end) = array_map('intval', explode('-', substr($range, 6), 2)) + array(0); if ('' !== $end) { - $this->maxlen = $end - $start; + $this->maxlen = $end - $start + 1; } else { $end = $this->file->getSize() - 1; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index 23f93f7a76..4f749a1ef0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -61,7 +61,7 @@ class BinaryFileResponseTest extends \PHPUnit_Framework_TestCase $request->headers->set('If-Range', $etag); $request->headers->set('Range', 'bytes=1-4'); - $this->expectOutputString('IF8'); + $this->expectOutputString('IF87'); $response = clone $response; $response->prepare($request); $response->sendContent();