Example #1
0
 /**
  * Handle a 304 response and ensure that it is still valid
  *
  * @param RequestInterface $request          Request that was sent
  * @param Response         $validateResponse Response received
  * @param Response         $response         Original cached response
  *
  * @return bool Returns true if valid, false if invalid
  */
 protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
 {
     static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');
     // Make sure that this response has the same ETag
     if ($validateResponse->getEtag() != $response->getEtag()) {
         return false;
     }
     // Replace cached headers with any of these headers from the
     // origin server that might be more up to date
     $modified = false;
     foreach ($replaceHeaders as $name) {
         if ($validateResponse->hasHeader($name)) {
             $modified = true;
             $response->setHeader($name, $validateResponse->getHeader($name));
         }
     }
     // Store the updated response in cache
     if ($modified && $this->canCache->canCacheResponse($response)) {
         $this->storage->cache($request, $response);
     }
     return true;
 }