Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #107 from ezimuel/fix/expires-zero
Browse files Browse the repository at this point in the history
Allow the usage of "Expires: 0" header
  • Loading branch information
weierophinney committed Jan 25, 2017
2 parents 29402ee + aa4ee94 commit 78d1d96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Header/Expires.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace Zend\Http\Header;

use DateTime;
use DateTimeZone;

/**
* Expires Header
*
Expand All @@ -25,4 +28,13 @@ public function getFieldName()
{
return 'Expires';
}


public function setDate($date)
{
if ($date === '0' || $date === 0) {
$date = date(DATE_W3C, 0); // Thu, 01 Jan 1970 00:00:00 GMT
}
return parent::setDate($date);
}
}
14 changes: 14 additions & 0 deletions test/Header/ExpiresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,18 @@ public function testPreventsCRLFAttackViaFromString()
{
$header = Expires::fromString("Expires: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent");
}

public function testExpiresSetToZero()
{
$expires = Expires::fromString("Expires: 0");
$this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString());

$expires = new Expires();
$expires->setDate('0');
$this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString());

$expires = new Expires();
$expires->setDate(0);
$this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString());
}
}

0 comments on commit 78d1d96

Please sign in to comment.