Skip to content

Commit

Permalink
Improved Cache-Control header when no-cache is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
dlsniper authored and fabpot committed Dec 11, 2012
1 parent f853fc3 commit 1ab4923
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -245,6 +245,12 @@ public function prepare(Request $request)
$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;
}

Expand Down Expand Up @@ -686,8 +692,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;
Expand Down

0 comments on commit 1ab4923

Please sign in to comment.