8000 [HttpFoundation] Postpone setting the date header on a Response · symfony/symfony@2ad3b0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ad3b0d

Browse files
committed
[HttpFoundation] Postpone setting the date header on a Response
1 parent 567af65 commit 2ad3b0d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ public function __construct($content = '', $status = 200, $headers = array())
202202
$this->setContent($content);
203203
$this->setStatusCode($status);
204204
$this->setProtocolVersion('1.0');
205-
if (!$this->headers->has('Date')) {
206-
$this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
207-
}
208205
}
209206

210207
/**
@@ -333,6 +330,10 @@ public function sendHeaders()
333330
return $this;
334331
}
335332

333+
if (!$this->headers->has('Date')) {
334+
$this->setDate(new \DateTime());
335+
}
336+
336337
// status
337338
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
338339

@@ -644,7 +645,11 @@ public function mustRevalidate()
644645
*/
645646
public function getDate()
646647
{
647-
return $this->headers->getDate('Date', new \DateTime());
648+
if (!$this->headers->has('Date')) {
649+
$this->setDate(new \DateTime());
650+
}
651+
652+
return $this->headers->getDate('Date');
648653
}
649654

650655
/**

0 commit comments

Comments
 (0)
0