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:
commit
28ae2d7240
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user