Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/StaticCaching/Middleware/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,18 @@ private function outputRefreshResponse($request)
private function addEtagToResponse($request, $response)
{
if (! $response->isRedirect() && $content = $response->getContent()) {
$response
->setEtag(md5($content))
->isNotModified($request);
// 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;
Expand Down
Loading