Improved Cache-Control header when no-cache is sent

This commit is contained in:
Florin Patan 2012-11-17 12:57:00 +02:00 committed by Fabien Potencier
parent f853fc3906
commit 1ab492394c

View File

@ -245,6 +245,12 @@ class Response
$this->setProtocolVersion('1.1'); $this->setProtocolVersion('1.1');
} }
// Check if we need to send extra expire info headers
if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
$this->headers->set('pragma', 'no-cache');
$this->headers->set('expires', -1);
}
return $this; return $this;
} }
@ -686,8 +692,14 @@ class Response
return $age; return $age;
} }
if (null !== $this->getExpires()) { $expiry = $this->getExpires();
return $this->getExpires()->format('U') - $this->getDate()->format('U');
if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) {
return $expiry;
}
if (null !== $expiry) {
return $expiry->format('U') - $this->getDate()->format('U');
} }
return null; return null;