Skip to content

Commit

Permalink
chore: Make changes for TYPO3 v12
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbroens committed Dec 12, 2024
1 parent 69ccae6 commit fd75e13
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
16 changes: 9 additions & 7 deletions Classes/Middleware/CacheHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand Down Expand Up @@ -41,9 +42,12 @@ class CacheHeaders implements MiddlewareInterface
* - Return status '200 OK' when ETag has changed (content has changed)
* - Send header 'cache-control: no-cache'
*
* IMPORTANT NOTE: Keep in mind when using "nonce" the browser (and TYPO3) will disable client side caching.
*
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
* @throws AspectNotFoundException
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
Expand All @@ -54,17 +58,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
&& (bool)$GLOBALS['TSFE']->config['config']['OpenGemeenten\CmsFrontend.']['sendCacheHeaders'] === true
&& $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
&& $GLOBALS['TSFE']->isStaticCacheble()
&& !$GLOBALS['TSFE']->isBackendUserLoggedIn()
&& !$GLOBALS['TSFE']->doWorkspacePreview()
&& (
empty($GLOBALS['TSFE']->config['config']['sendCacheHeaders_onlyWhenLoginDeniedInBranch'])
|| empty($GLOBALS['TSFE']->checkIfLoginAllowedInBranch())
)
&& !$GLOBALS['TSFE']->getContext()->getPropertyFromAspect('backend.user', 'isLoggedIn', false)
&& !$GLOBALS['TSFE']->getContext()->getPropertyFromAspect('workspace', 'isOffline', false)
) {
$configuration = $GLOBALS['TSFE']->config['config'];

// If cache headers are set within TYPO3, unset most of them
if ((bool)$configuration['sendCacheHeaders'] === true) {
if (isset($configuration['sendCacheHeaders'])
&& (bool)$configuration['sendCacheHeaders'] === true
) {
$response = $response->withoutHeader('cache-control');
$response = $response->withoutHeader('expires');
$response = $response->withoutHeader('pragma');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extensions.opengemeenten_cacheheaders {
cacheHeaders {
sendCacheHeaders = 0
pattern = ^("[0-9a-fA-F]*)(\b-gzip\b|)(")$
replacement = $1$3
sendCacheHeaders = 1
pattern = ^([W]\/|)(")([0-9a-fA-F]*)(\b-gzip\b|)(")$
replacement = $3
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ The `ETag` header is a `md5` hash of the content of a page and will be calculate
When the HTTP status code `304, Not Modified` is send, no content will be send, keeping the response very small.
See`Symfony\Component\HttpFoundation`

## IMPORTANT NOTE

When using CSP in TYPO3 with `nonce`, browsers (and TYPO3) will disable client-side caching.

## More info

You can find a great tutorial on Medium by Alex Barashkov:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"typo3/cms-frontend": "^10.4 || ^11.5"
"typo3/cms-frontend": "^12.4"
},
"extra": {
"typo3/cms": {
Expand Down

0 comments on commit fd75e13

Please sign in to comment.