mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 04:49:36 +00:00
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:
parent
185107f4e1
commit
02869f2aa7
1 changed files with 3 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue