Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b8b5ae

Browse files
author
Benoît Burnichon
committed
Verify edge case where no last-modified header is available
1 parent9171f8e commit6b8b5ae

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

‎src/Symfony/Component/HttpFoundation/BinaryFileResponse.php‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function prepare(Request $request)
217217
$this->maxlen =0;
218218
}elseif ($request->headers->has('Range')) {
219219
// Process the range headers.
220-
if (!$request->headers->has('If-Range') ||$this->getEtag() ==$request->headers->get('If-Range') ||$this->getLastModified()->format('D, d M Y H:i:s').' GMT' ==$request->headers->get('If-Range')) {
220+
if (!$request->headers->has('If-Range') ||$this->hasValidIfRangeHeader($request->headers->get('If-Range'))) {
221221
$range =$request->headers->get('Range');
222222
$fileSize =$this->file->getSize();
223223

@@ -250,6 +250,19 @@ public function prepare(Request $request)
250250
return$this;
251251
}
252252

253+
privatefunctionhasValidIfRangeHeader($header)
254+
{
255+
if ($this->getEtag() ==$header) {
256+
returntrue;
257+
}
258+
259+
if (null ===$lastModified =$this->getLastModified()) {
260+
returnfalse;
261+
}
262+
263+
return$lastModified->format('D, d M Y H:i:s') .' GMT' ==$header;
264+
}
265+
253266
/**
254267
* Sends the file.
255268
*/

‎src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ public function provideRanges()
122122
);
123123
}
124124

125+
publicfunctiontestRangeRequestsWithoutLastModifiedDate()
126+
{
127+
// prevent auto last modified
128+
$response = BinaryFileResponse::create(__DIR__.'/File/Fixtures/test.gif',200,array('Content-Type' =>'application/octet-stream'),true,null,false,false);
129+
130+
// prepare a request for a range of the testing file
131+
$request = Request::create('/');
132+
$request->headers->set('If-Range',date('D, d M Y H:i:s') .' GMT');
133+
$request->headers->set('Range','bytes=1-4');
134+
135+
$this->expectOutputString(file_get_contents(__DIR__.'/File/Fixtures/test.gif'));
136+
$response =clone$response;
137+
$response->prepare($request);
138+
$response->sendContent();
139+
140+
$this->assertEquals(200,$response->getStatusCode());
141+
$this->assertNull($response->headers->get('Content-Range'));
142+
}
143+
125144
/**
126145
* @dataProvider provideFullFileRanges
127146
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp