Issue Bug Closed

#106065Too long X-TYPO3-Cache-Tags Header

Pascal Geldmacher 02/03/25, 12:14 updated 02/03/25, 13:15

Description

I get an 500 Server error If I have the FE debug modus active and the X-TYPO3-Cache-Tags will set.
There is a page which has a array with 500 CacheTags. In the array are pages, sys_file, sys_file_metadata cachetags.

The middleware CacheDataCollectorAttribute generates the X-TYPO3-Cache-Tags header and run in a 500 error because the header is too long.

  public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // Middlewares are shared services. With sub requests in mind, we need to take care
        // existing data of the parent request is not overwritten by a sub request. We thus
        // back up any existing data, create a new CacheDataCollector, dispatch the request,
        // and reset before returning the response.
        // @todo: We could argue sub requests should run their own container instance, but
        //        this has more impact and has not been sorted out, yet.
        $backup = $this->cacheDataCollector;
        $this->cacheDataCollector = new CacheDataCollector();
        $request = $request->withAttribute('frontend.cache.collector', $this->cacheDataCollector);
        $response = $handler->handle($request);
        if ($this->isDebugModeEnabled()) {
            $cacheTags = array_map(fn(CacheTag $cacheTag) => $cacheTag->name, $this->cacheDataCollector->getCacheTags());
            sort($cacheTags);
            $response = $response->withHeader('X-TYPO3-Cache-Tags', implode(',', $cacheTags));
            $response = $response->withHeader('X-TYPO3-Cache-Lifetime', (string)$this->cacheDataCollector->resolveLifetime());
        }
        foreach ($this->cacheDataCollector->getCacheEntries() as $deferredCacheItem) {
            $deferredCacheItem($request);
        }
        $this->cacheDataCollector = $backup;
        return $response;
    }

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.