Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Classes/Middleware/FallbackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ protected function handleViaFallback(ServerRequestInterface $request): ResponseI
throw new Exception('The path is not in the cache directory', 348923472);
}

return new HtmlResponse(GeneralUtility::getUrl($possibleStaticFile), 200, $headers);
// The file might be removed (e.g. by a cache flush) after the checks above
$content = GeneralUtility::getUrl($possibleStaticFile);
if (false === $content) {
throw new Exception('StaticFileCache file could not be read', 1795530268);
}

return new HtmlResponse($content, 200, $headers);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions Tests/Unit/Middleware/FallbackMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ public function testMissingStaticFileSkipsFallback(): void
$this->assertHandledByTypo3($this->getMiddleware());
}

public function testStaticFileRemovedWhileReadingSkipsFallback(): void
{
file_put_contents($this->staticFile, 'cached');

// The cache directory is requested after the file checks and before the file is read:
// remove the file at this point, like a concurrent cache flush would do.
$this->cacheService = $this->createStub(CacheService::class);
$this->cacheService->method('getAbsoluteBaseDirectory')->willReturnCallback(function (): string {
unlink($this->staticFile);

return $this->cacheDirectory;
});

$this->assertHandledByTypo3($this->getMiddleware());
}

public function testFileOutsideOfCacheDirectorySkipsFallback(): void
{
file_put_contents($this->staticFile, 'cached');
Expand Down
Loading