From 1ab492394c540f5ff857fec2a94eea78a4a54252 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Sat, 17 Nov 2012 12:57:00 +0200 Subject: [PATCH] Improved Cache-Control header when no-cache is sent --- .../Component/HttpFoundation/Response.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 2d19dd63aa..4d8992a7c3 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -245,6 +245,12 @@ class Response $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; } @@ -686,8 +692,14 @@ class Response 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;