1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 18:43:22 +01:00

Merge pull request #246 from thewilkybarkid/is_fresh

Response is only stale if the age is greater than the max-age
This commit is contained in:
Michael Dowling 2013-02-26 10:26:53 -08:00
commit 28ae2d7240
2 changed files with 7 additions and 2 deletions

View File

@ -845,7 +845,8 @@ class Response extends AbstractMessage
/**
* Check if the response is considered fresh.
*
* A response is considered fresh when its age is less than the freshness lifetime (maximum age) of the response.
* A response is considered fresh when its age is less than or equal to the freshness lifetime (maximum age) of the
* response.
*
* @return bool|null
*/
@ -853,7 +854,7 @@ class Response extends AbstractMessage
{
$fresh = $this->getFreshness();
return $fresh === null ? null : $this->getFreshness() > 0;
return $fresh === null ? null : $fresh >= 0;
}
/**

View File

@ -759,6 +759,10 @@ class ResponseTest extends \Guzzle\Tests\GuzzleTestCase
$this->assertEquals(20, $response->getFreshness());
$this->assertTrue($response->isFresh());
$response->setHeader('Age', 120);
$this->assertEquals(0, $response->getFreshness());
$this->assertTrue($response->isFresh());
$response->setHeader('Age', 150);
$this->assertEquals(-30, $response->getFreshness());
$this->assertFalse($response->isFresh());