Set Date header in Response constructor already
This commit is contained in:
parent
6b4cfd6a25
commit
3a7fa7ede2
@ -201,6 +201,11 @@ class Response
|
||||
$this->setContent($content);
|
||||
$this->setStatusCode($status);
|
||||
$this->setProtocolVersion('1.0');
|
||||
|
||||
/* RFC2616 - 14.18 says all Responses need to have a Date */
|
||||
if (!$this->headers->has('Date')) {
|
||||
$this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,6 +334,7 @@ class Response
|
||||
return $this;
|
||||
}
|
||||
|
||||
/* RFC2616 - 14.18 says all Responses need to have a Date */
|
||||
if (!$this->headers->has('Date')) {
|
||||
$this->setDate(\DateTime::createFromFormat('U', time()));
|
||||
}
|
||||
@ -612,6 +618,11 @@ class Response
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
/*
|
||||
RFC2616 - 14.18 says all Responses need to have a Date.
|
||||
Make sure we provide one even if it the header
|
||||
has been removed in the meantime.
|
||||
*/
|
||||
if (!$this->headers->has('Date')) {
|
||||
$this->setDate(\DateTime::createFromFormat('U', time()));
|
||||
}
|
||||
|
@ -276,8 +276,10 @@ class ResponseTest extends ResponseTestCase
|
||||
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the date when the header has been modified');
|
||||
|
||||
$response = new Response('', 200);
|
||||
$now = $this->createDateTimeNow();
|
||||
$response->headers->remove('Date');
|
||||
$this->assertInstanceOf('\DateTime', $response->getDate());
|
||||
$date = $response->getDate();
|
||||
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the current Date when the header has previously been removed');
|
||||
}
|
||||
|
||||
public function testGetMaxAge()
|
||||
|
Reference in New Issue
Block a user