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 @@ -50,13 +50,15 @@ public function __construct(Cacher $cacher, Session $nocache)
5050 public function handle ($ request , Closure $ next )
5151 {
5252 if ($ response = $ this ->attemptToServeCachedResponse ($ request )) {
53- return $ response ;
53+ return $ this -> addEtagToResponse ( $ request , $ response) ;
5454 }
5555
5656 $ lock = $ this ->createLock ($ request );
5757
5858 try {
59- return $ lock ->block ($ this ->lockFor , fn () => $ this ->handleRequest ($ request , $ next ));
59+ return $ lock ->block ($ this ->lockFor ,
60+ fn () => $ this ->addEtagToResponse ($ request , $ this ->handleRequest ($ request , $ next ))
61+ );
6062 } catch (LockTimeoutException $ e ) {
6163 return $ this ->outputRefreshResponse ($ request );
6264 }
@@ -229,4 +231,15 @@ private function outputRefreshResponse($request)
229231
230232 return response ($ html , 503 , ['Retry-After ' => 1 ]);
231233 }
234+
235+ private function addEtagToResponse ($ request , $ response )
236+ {
237+ if (! $ response ->isRedirect () && $ content = $ response ->getContent ()) {
238+ $ response
239+ ->setEtag (md5 ($ content ))
240+ ->isNotModified ($ request );
241+ }
242+
243+ return $ response ;
244+ }
232245}
You can’t perform that action at this time.
0 commit comments