[2.0][HttpFoundation] Improved Cache-Control header when no-cache is sent #6037

Closed
wants to merge 1 commit into
from
View
18 src/Symfony/Component/HttpFoundation/Response.php
@@ -143,6 +143,14 @@ public function prepare()
if ($this->headers->has('Transfer-Encoding')) {
$this->headers->remove('Content-Length');
}
+
+
@fabpot
fabpot Dec 10, 2012

You should remove one blank line here.

+ // 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);
+ }
+
}
/**
@@ -525,8 +533,14 @@ public function getMaxAge()
return $age;
}
- if (null !== $this->getExpires()) {
- return $this->getExpires()->format('U') - $this->getDate()->format('U');
+ $expiry = $this->getExpires();
+
+ if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) {
+ return $expiry;
+ }
+
+ if (null !== $expiry) {
+ return $expiry->format('U') - $this->getDate()->format('U');
}
return null;