Skip to content

Commit 70aec68

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: fix merge [FrameworkBundle] Allow to specify `null` for exception mapping configuration values Fix BinaryFileResponse content type detection logic [Notifier] [Expo] Throw exception on error-response from expo api Bump Symfony version to 6.1.6 Update VERSION for 6.1.5 Update CHANGELOG for 6.1.5 Bump Symfony version to 6.0.14 Update VERSION for 6.0.13 Update CHANGELOG for 6.0.13 Bump Symfony version to 5.4.14 Update VERSION for 5.4.13 Update CHANGELOG for 5.4.13 Bump Symfony version to 4.4.47 Update VERSION for 4.4.46 Update CONTRIBUTORS for 4.4.46 Update CHANGELOG for 4.4.46 [Security] Fix login url matching when app is not run with url rewriting or from a sub folder [symfony/mailjet-mailer] Fix bug #47701
2 parents 35c48a0 + c695ce3 commit 70aec68

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

BinaryFileResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public function setContentDisposition(string $disposition, string $filename = ''
179179

180180
public function prepare(Request $request): static
181181
{
182-
parent::prepare($request);
183-
184182
if ($this->isInformational() || $this->isEmpty()) {
183+
parent::prepare($request);
184+
185185
$this->maxlen = 0;
186186

187187
return $this;
@@ -191,6 +191,8 @@ public function prepare(Request $request): static
191191
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
192192
}
193193

194+
parent::prepare($request);
195+
194196
$this->offset = 0;
195197
$this->maxlen = -1;
196198

Tests/BinaryFileResponseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,32 @@ public function testPrepareNotAddingContentTypeHeaderIfNoContentResponse()
387387
$this->assertFalse($response->headers->has('Content-Type'));
388388
}
389389

390+
public function testContentTypeIsCorrectlyDetected()
391+
{
392+
$response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif');
393+
394+
$request = Request::create('/');
395+
$response->prepare($request);
396+
397+
$this->assertSame(200, $response->getStatusCode());
398+
$this->assertSame('image/gif', $response->headers->get('Content-Type'));
399+
}
400+
401+
public function testContentTypeIsNotGuessedWhenTheFileWasNotModified()
402+
{
403+
$response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif');
404+
$response->setAutoLastModified();
405+
406+
$request = Request::create('/');
407+
$request->headers->set('If-Modified-Since', $response->getLastModified()->format('D, d M Y H:i:s').' GMT');
408+
$isNotModified = $response->isNotModified($request);
409+
$this->assertTrue($isNotModified);
410+
$response->prepare($request);
411+
412+
$this->assertSame(304, $response->getStatusCode());
413+
$this->assertFalse($response->headers->has('Content-Type'));
414+
}
415+
390416
protected function provideResponse()
391417
{
392418
return new BinaryFileResponse(__DIR__.'/../README.md', 200, ['Content-Type' => 'application/octet-stream']);

0 commit comments

Comments
 (0)