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
This commit is contained in:
commit
a44ceb3156
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user