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

Allow the usage of "Expires: 0" header #107

Merged
merged 2 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also allow an integer 0 value?

Copy link
Contributor Author

@ezimuel ezimuel Jan 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable. Just updated the PR.

$date = date(DATE_W3C, 0); // Thu, 01 Jan 1970 00:00:00 GMT
}
return parent::setDate($date);
}
}
10 changes: 10 additions & 0 deletions test/Header/ExpiresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ 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());
}
}