diff --git a/Classes/Event/ProcessResourcesEvent.php b/Classes/Event/ProcessResourcesEvent.php new file mode 100644 index 0000000..1bad840 --- /dev/null +++ b/Classes/Event/ProcessResourcesEvent.php @@ -0,0 +1,23 @@ +resources = $resources; + } + + public function getResources(): array + { + return $this->resources; + } + + public function setResources(array $resources): void + { + $this->resources = $resources; + } +} diff --git a/Classes/Http/ResourcePusher.php b/Classes/Http/ResourcePusher.php index 3cbbe69..70aaf06 100644 --- a/Classes/Http/ResourcePusher.php +++ b/Classes/Http/ResourcePusher.php @@ -10,11 +10,14 @@ * of the License, or any later version. */ +use B13\Http2\Event\ProcessResourcesEvent; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; use TYPO3\CMS\Core\Http\NormalizedParams; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\PathUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -36,10 +39,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface /** @var NormalizedParams $normalizedParams */ $normalizedParams = $request->getAttribute('normalizedParams'); if (is_array($resources) && $normalizedParams->isHttps()) { - foreach ($resources['scripts'] ?? [] as $resource) { + $eventDispatcher = GeneralUtility::makeInstance(EventDispatcher::class); + $event = $eventDispatcher->dispatch(new ProcessResourcesEvent($resources)); + $resources = $event->getResources(); + foreach ($resources['scripts'] ?? [] as $resource) { $response = $this->addPreloadHeaderToResponse($response, $resource, 'script'); } - foreach ($resources['styles'] ?? [] as $resource) { + foreach ($resources['styles'] ?? [] as $resource) { $response = $this->addPreloadHeaderToResponse($response, $resource, 'style'); } }