diff --git a/src/Http/Responses/DataResponse.php b/src/Http/Responses/DataResponse.php index b91d885d685..83e1e8bc39d 100644 --- a/src/Http/Responses/DataResponse.php +++ b/src/Http/Responses/DataResponse.php @@ -42,12 +42,6 @@ public function toResponse($request) ->make($this->contents()) ->withHeaders($this->headers); - if ($content = $response->getContent()) { - $response - ->setEtag(md5($content)) - ->isNotModified($request); - } - ResponseCreated::dispatch($response, $this->data); return $response; diff --git a/src/StaticCaching/Middleware/Cache.php b/src/StaticCaching/Middleware/Cache.php index 68265a4bfff..86731fa0e3e 100644 --- a/src/StaticCaching/Middleware/Cache.php +++ b/src/StaticCaching/Middleware/Cache.php @@ -50,15 +50,13 @@ public function __construct(Cacher $cacher, Session $nocache) public function handle($request, Closure $next) { if ($response = $this->attemptToServeCachedResponse($request)) { - return $this->addEtagToResponse($request, $response); + return $response; } $lock = $this->createLock($request); try { - return $lock->block($this->lockFor, - fn () => $this->addEtagToResponse($request, $this->handleRequest($request, $next)) - ); + return $lock->block($this->lockFor, fn () => $this->handleRequest($request, $next)); } catch (LockTimeoutException $e) { return $this->outputRefreshResponse($request); } @@ -231,24 +229,4 @@ private function outputRefreshResponse($request) return response($html, 503, ['Retry-After' => 1]); } - - private function addEtagToResponse($request, $response) - { - if (! $response->isRedirect() && $content = $response->getContent()) { - // Clear any potentially stale cache-related headers that might interfere - $response->headers->remove('ETag'); - $response->headers->remove('Last-Modified'); - - // Set fresh ETag based on current content - $response->setEtag(md5($content)); - - // Only call isNotModified() if request has cache validation headers - // This prevents 304 responses to clients that haven't sent If-None-Match or If-Modified-Since - if ($request->headers->has('If-None-Match') || $request->headers->has('If-Modified-Since')) { - $response->isNotModified($request); - } - } - - return $response; - } } diff --git a/tests/FrontendTest.php b/tests/FrontendTest.php index b7b0b691a80..15d2229e344 100644 --- a/tests/FrontendTest.php +++ b/tests/FrontendTest.php @@ -1064,32 +1064,4 @@ public function it_protects_404_pages() ->get('/does-not-exist') ->assertStatus(404); } - - #[Test] - public function it_sets_etag_header_and_returns_304_when_content_matches() - { - $this->withStandardBlueprints(); - $this->withFakeViews(); - $this->viewShouldReturnRaw('layout', '{{ template_content }}'); - $this->viewShouldReturnRaw('default', '