handle($request); $path = $request->getUri()->getPath(); if ( !\in_array($request->getMethod(), ['GET', 'HEAD'], true) || $response->getStatusCode() !== 200 || ($path !== '/_json' && !str_starts_with($path, '/_json/')) || isset($request->getCookieParams()['fe_typo_user']) ) { return $response; } $etag = '"' . md5((string)$response->getBody()) . '"'; // mod_deflate suffixes the ETag it compressed ("-gzip"); // browsers send that form back, so accept it too (0054-FE 5.3). $ifNoneMatch = str_replace('-gzip"', '"', trim($request->getHeaderLine('If-None-Match'))); if ($ifNoneMatch !== '' && str_contains($ifNoneMatch, $etag)) { return (new Response()) ->withStatus(304) ->withHeader('ETag', $etag) ->withHeader('Cache-Control', 'no-cache') ->withHeader('Expires', '0'); } return $response ->withHeader('Cache-Control', 'no-cache') ->withoutHeader('Pragma') ->withHeader('Expires', '0') ->withHeader('ETag', $etag); } }