Skip to content

Commit 39ced1a

Browse files
authored
[5.x] Revert etags (#13933)
1 parent 41cc8b2 commit 39ced1a

3 files changed

Lines changed: 2 additions & 58 deletions

File tree

src/Http/Responses/DataResponse.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ public function toResponse($request)
4242
->make($this->contents())
4343
->withHeaders($this->headers);
4444

45-
if ($content = $response->getContent()) {
46-
$response
47-
->setEtag(md5($content))
48-
->isNotModified($request);
49-
}
50-
5145
ResponseCreated::dispatch($response, $this->data);
5246

5347
return $response;

src/StaticCaching/Middleware/Cache.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ public function __construct(Cacher $cacher, Session $nocache)
5050
public function handle($request, Closure $next)
5151
{
5252
if ($response = $this->attemptToServeCachedResponse($request)) {
53-
return $this->addEtagToResponse($request, $response);
53+
return $response;
5454
}
5555

5656
$lock = $this->createLock($request);
5757

5858
try {
59-
return $lock->block($this->lockFor,
60-
fn () => $this->addEtagToResponse($request, $this->handleRequest($request, $next))
61-
);
59+
return $lock->block($this->lockFor, fn () => $this->handleRequest($request, $next));
6260
} catch (LockTimeoutException $e) {
6361
return $this->outputRefreshResponse($request);
6462
}
@@ -231,24 +229,4 @@ private function outputRefreshResponse($request)
231229

232230
return response($html, 503, ['Retry-After' => 1]);
233231
}
234-
235-
private function addEtagToResponse($request, $response)
236-
{
237-
if (! $response->isRedirect() && $content = $response->getContent()) {
238-
// Clear any potentially stale cache-related headers that might interfere
239-
$response->headers->remove('ETag');
240-
$response->headers->remove('Last-Modified');
241-
242-
// Set fresh ETag based on current content
243-
$response->setEtag(md5($content));
244-
245-
// Only call isNotModified() if request has cache validation headers
246-
// This prevents 304 responses to clients that haven't sent If-None-Match or If-Modified-Since
247-
if ($request->headers->has('If-None-Match') || $request->headers->has('If-Modified-Since')) {
248-
$response->isNotModified($request);
249-
}
250-
}
251-
252-
return $response;
253-
}
254232
}

tests/FrontendTest.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,32 +1064,4 @@ public function it_protects_404_pages()
10641064
->get('/does-not-exist')
10651065
->assertStatus(404);
10661066
}
1067-
1068-
#[Test]
1069-
public function it_sets_etag_header_and_returns_304_when_content_matches()
1070-
{
1071-
$this->withStandardBlueprints();
1072-
$this->withFakeViews();
1073-
$this->viewShouldReturnRaw('layout', '{{ template_content }}');
1074-
$this->viewShouldReturnRaw('default', '<h1>Test Page</h1>');
1075-
1076-
$this->createPage('about');
1077-
1078-
$response = $this->get('/about');
1079-
$response->assertStatus(200);
1080-
1081-
$content = trim($response->content());
1082-
$this->assertEquals('<h1>Test Page</h1>', $content);
1083-
1084-
$etag = $response->headers->get('ETag');
1085-
$this->assertEquals('"'.md5($content).'"', $etag); // Per spec, the quotes need to be in the string.
1086-
1087-
$response = $this->get('/about', ['If-None-Match' => $etag]);
1088-
$response->assertStatus(304);
1089-
$this->assertEmpty($response->content());
1090-
1091-
$response = $this->get('/about', ['If-None-Match' => '"wrong-etag"']);
1092-
$response->assertStatus(200);
1093-
$this->assertEquals('<h1>Test Page</h1>', trim($response->content()));
1094-
}
10951067
}

0 commit comments

Comments
 (0)