Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  [Finder] Fix using `==` as default operator in `DateComparator`
  [HttpFoundation] Avoid mime type guess with temp files in `BinaryFileResponse`
  choose the correctly cased class name for the MariaDB platform
  • Loading branch information
fabpot committed Dec 30, 2024
2 parents e88a66c + b5567e7 commit 62d1a43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ public function prepare(Request $request): static
}

if (!$this->headers->has('Content-Type')) {
$this->headers->set('Content-Type', $this->file->getMimeType() ?: 'application/octet-stream');
$mimeType = null;
if (!$this->tempFileObject) {
$mimeType = $this->file->getMimeType();
}

$this->headers->set('Content-Type', $mimeType ?: 'application/octet-stream');
}

parent::prepare($request);
Expand Down
11 changes: 11 additions & 0 deletions Tests/BinaryFileResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,15 @@ public function testSetChunkSizeTooSmall()

$response->setChunkSize(0);
}

public function testCreateFromTemporaryFileWithoutMimeType()
{
$file = new \SplTempFileObject();
$file->fwrite('foo,bar');

$response = new BinaryFileResponse($file);
$response->prepare(new Request());

$this->assertSame('application/octet-stream', $response->headers->get('Content-Type'));
}
}

0 comments on commit 62d1a43

Please sign in to comment.