Use Symfony's built-in ETag handling for HTTP caching

Replace manual If-None-Match comparison with Response::setEtag() and
Response::isNotModified(), which properly handles ETag quoting, weak
vs strong comparison, and 304 response cleanup. Fixes PHPStan return
type error and CI test failures.
This commit is contained in:
Sebastian Almberg 2026-02-08 15:35:49 +01:00
parent 9ec6e3db70
commit 44c5d9d727

View file

@ -92,17 +92,12 @@ class KiCadApiController extends AbstractController
* Creates a JSON response with HTTP cache headers (ETag and Cache-Control).
* Returns 304 Not Modified if the client's ETag matches.
*/
private function createCachedJsonResponse(Request $request, array $data, int $maxAge): JsonResponse
private function createCachedJsonResponse(Request $request, array $data, int $maxAge): Response
{
$etag = '"' . md5(json_encode($data)) . '"';
if ($request->headers->get('If-None-Match') === $etag) {
return new Response('', Response::HTTP_NOT_MODIFIED);
}
$response = new JsonResponse($data);
$response->setEtag(md5(json_encode($data)));
$response->headers->set('Cache-Control', 'private, max-age=' . $maxAge);
$response->headers->set('ETag', $etag);
$response->isNotModified($request);
return $response;
}