Skip to content

Commit

Permalink
[HttpFoundation] Postpone setting the date header on a Response
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jun 9, 2015
1 parent 567af65 commit 2ad3b0d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -202,9 +202,6 @@ public function __construct($content = '', $status = 200, $headers = array())
$this->setContent($content);
$this->setStatusCode($status);
$this->setProtocolVersion('1.0');
if (!$this->headers->has('Date')) {
$this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
}
}

/**
Expand Down Expand Up @@ -333,6 +330,10 @@ public function sendHeaders()
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);

Expand Down Expand Up @@ -644,7 +645,11 @@ public function mustRevalidate()
*/
public function getDate()
{
return $this->headers->getDate('Date', new \DateTime());
if (!$this->headers->has('Date')) {
$this->setDate(new \DateTime());
}

return $this->headers->getDate('Date');
}

/**
Expand Down

0 comments on commit 2ad3b0d

Please sign in to comment.