From 2ad3b0d8902cb582babadb46ca38b68414d7f39a Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Mon, 8 Jun 2015 19:37:36 +0100 Subject: [PATCH] [HttpFoundation] Postpone setting the date header on a Response --- src/Symfony/Component/HttpFoundation/Response.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 6641e51023..38174dd969 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -202,9 +202,6 @@ class Response $this->setContent($content); $this->setStatusCode($status); $this->setProtocolVersion('1.0'); - if (!$this->headers->has('Date')) { - $this->setDate(new \DateTime(null, new \DateTimeZone('UTC'))); - } } /** @@ -333,6 +330,10 @@ class Response return $this; } + if (!$this->headers->has('Date')) { + $this->setDate(new \DateTime()); + } + // status header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode); @@ -644,7 +645,11 @@ class Response */ public function getDate() { - return $this->headers->getDate('Date', new \DateTime()); + if (!$this->headers->has('Date')) { + $this->setDate(new \DateTime()); + } + + return $this->headers->getDate('Date'); } /**