mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-03 13:59:35 +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
9ec6e3db70
commit
44c5d9d727
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).
|
* Creates a JSON response with HTTP cache headers (ETag and Cache-Control).
|
||||||
* Returns 304 Not Modified if the client's ETag matches.
|
* 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 = new JsonResponse($data);
|
||||||
|
$response->setEtag(md5(json_encode($data)));
|
||||||
$response->headers->set('Cache-Control', 'private, max-age=' . $maxAge);
|
$response->headers->set('Cache-Control', 'private, max-age=' . $maxAge);
|
||||||
$response->headers->set('ETag', $etag);
|
$response->isNotModified($request);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue