Skip to content

Commit 783ee89

Browse files
committed
bug #18080 [HttpFoundation] Set the Content-Range header if the requested Range is unsatisfied (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] Set the Content-Range header if the requested Range is unsatisfied | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This is a followup to symfony/symfony#17150 (comment) [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) specifies the Content-Range header SHOULD be included with a *416 Requested Range Not Satisfiable* response: > When this status code is returned for a byte-range request, the response SHOULD include a Content-Range entity-header field specifying the current length of the selected resource (see section 14.16). This response MUST NOT use the multipart/byteranges content- type. [RFC 7233](https://tools.ietf.org/html/rfc7233#section-4.2) specifies what should be the header's value. It's in the "Request for comments" state, but it's the best definition I could find. This value is valid according to rfc2616 as well. Commits ------- 54329d8 [HttpFoundation] Set the Content-Range header if the requested Range is unsatisfied
2 parents 28e1352 + 58176c6 commit 783ee89

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

BinaryFileResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public function prepare(Request $request)
252252
if ($start <= $end) {
253253
if ($start < 0 || $end > $fileSize - 1) {
254254
$this->setStatusCode(416);
255+
$this->headers->set('Content-Range', sprintf('bytes */%s', $fileSize));
255256
} elseif ($start !== 0 || $end !== $fileSize - 1) {
256257
$this->maxlen = $end < $fileSize ? $end - $start + 1 : -1;
257258
$this->offset = $start;

Tests/BinaryFileResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function testInvalidRequests($requestRange)
211211
$response->sendContent();
212212

213213
$this->assertEquals(416, $response->getStatusCode());
214-
#$this->assertEquals('', $response->headers->get('Content-Range'));
214+
$this->assertEquals('bytes */35', $response->headers->get('Content-Range'));
215215
}
216216

217217
public function provideInvalidRanges()

0 commit comments

Comments
 (0)