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:
  fix detecting anonymous exception classes on Windows and PHP 7
  skip tests requiring the intl extension if it's not installed
  [RateLimiter] Fix DateInterval normalization
  re-add missing profiler shortcuts on profiler homepage
  Fix support for \SplTempFileObject in BinaryFileResponse
  [Security] Store original token in token storage when implicitly exiting impersonation
  [Cache] Fix clear() when using Predis
  • Loading branch information
nicolas-grekas committed Nov 5, 2024
2 parents cddd58b + 4f4d5a2 commit 306e795
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function setChunkSize(int $chunkSize): static
*/
public function setAutoLastModified(): static
{
$this->setLastModified(\DateTimeImmutable::createFromFormat('U', $this->file->getMTime()));
$this->setLastModified(\DateTimeImmutable::createFromFormat('U', $this->tempFileObject ? time() : $this->file->getMTime()));

return $this;
}
Expand Down Expand Up @@ -197,7 +197,9 @@ public function prepare(Request $request): static
$this->offset = 0;
$this->maxlen = -1;

if (false === $fileSize = $this->file->getSize()) {
if ($this->tempFileObject) {
$fileSize = $this->tempFileObject->fstat()['size'];
} elseif (false === $fileSize = $this->file->getSize()) {
return $this;
}
$this->headers->remove('Transfer-Encoding');
Expand Down
3 changes: 3 additions & 0 deletions Tests/BinaryFileResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ public function testCreateFromTemporaryFile()
$this->assertEquals('attachment; filename=temp', $response->headers->get('Content-Disposition'));

ob_start();
$response->setAutoLastModified();
$response->prepare(new Request());
$this->assertSame('7', $response->headers->get('Content-Length'));
$response->sendContent();
$string = ob_get_clean();
$this->assertSame('foo,bar', $string);
Expand Down

0 comments on commit 306e795

Please # to comment.