[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.
This commit is contained in:
parent
63bfd9ef79
commit
d9b91458f1
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user