diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index a212f065e0af..b0f0536c457e 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -226,7 +226,9 @@ public function remove($key) * @param string $key The parameter key * @param \DateTime $default The default value * - * @return \DateTime The filtered value + * @return null|\DateTime The filtered value + * + * @throws \RuntimeException When the HTTP header is not parseable * * @api */ diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index bb729f7cbfd6..7b68c3861f0d 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -430,7 +430,7 @@ public function mustRevalidate() */ public function getDate() { - return $this->headers->getDate('Date'); + return $this->headers->getDate('Date', new \DateTime()); } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php index a9acc7080c22..689e4b077e32 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php @@ -40,6 +40,10 @@ public function testGetDate() $now = $this->createDateTimeNow(); $response->headers->set('Date', $now->format(DATE_RFC2822)); $this->assertEquals(0, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified'); + + $response = new Response('', 200); + $response->headers->remove('Date'); + $this->assertInstanceOf('\DateTime', $response->getDate()); } public function testGetMaxAge()