File tree Expand file tree Collapse file tree
src/StaticCaching/Middleware Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -235,9 +235,18 @@ private function outputRefreshResponse($request)
235235 private function addEtagToResponse ($ request , $ response )
236236 {
237237 if (! $ response ->isRedirect () && $ content = $ response ->getContent ()) {
238- $ response
239- ->setEtag (md5 ($ content ))
240- ->isNotModified ($ request );
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+ }
241250 }
242251
243252 return $ response ;
You can’t perform that action at this time.
0 commit comments