Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a44ceb3

Browse filesBrowse files
committed
feature #14912 [HttpFoundation] Postpone setting the date header on a Response (jakzal)
This PR was merged into the 2.8 branch. Discussion ---------- [HttpFoundation] Postpone setting the date header on a Response | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14906 | License | MIT | Doc PR | - The only risk of doing this is if someone called `getDate()` and the date header was not present, the date might be slightly different than the one sent with the headers. `getDate()` could also set the date header first time it's requested (do a lazy initialisation). Commits ------- 2ad3b0d [HttpFoundation] Postpone setting the date header on a Response
2 parents f38296b + 2ad3b0d commit a44ceb3
Copy full SHA for a44ceb3

File tree

Expand file treeCollapse file tree

1 file changed

+9
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-4
lines changed

‎src/Symfony/Component/HttpFoundation/Response.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Response.php
+9-4Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.