merged branch dlsniper/fix-expiry (PR #6471)
This PR was squashed before being merged into the 2.1 branch (closes #6471).
Commits
-------
87b6cc2
Fix Expires when the header is -1
Discussion
----------
Fix Expires when the header is -1
This fixes the issue described in #6469.
Let me know if I've missed something.
Thanks.
---------------------------------------------------------------------------
by blaugueux at 2012-12-27T20:22:23Z
@dlsniper how can i help here, i really need to fix this issue
---------------------------------------------------------------------------
by dlsniper at 2012-12-27T20:28:53Z
I think @fabpot needs to get me some feedback on this but meanwhile you should try the proposed patch and let me know if it fixes the problem for you or I should add more tests to this.
Thanks!
---------------------------------------------------------------------------
by blaugueux at 2012-12-30T14:37:58Z
@dlsniper your patch is working great for me but it breaks tests. I agree that @fabpot point of view is required.
---------------------------------------------------------------------------
by dlsniper at 2012-12-30T18:38:38Z
@blaugueux Can you let me know what tests are failing? the one included in this PR or some custom ones from you? If it's the later, can you share some so that I can add them?
Thanks!
---------------------------------------------------------------------------
by arendjantetteroo at 2013-01-02T12:45:48Z
The headerbag fix works here. I'm not sure if the extra check in Response is really necessary, it works here without it.
This commit is contained in:
commit
d9a55ed8cf
@ -235,6 +235,14 @@ class HeaderBag implements \IteratorAggregate, \Countable
|
|||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-1 === $value) {
|
||||||
|
/**
|
||||||
|
* Since we need to return a valid date time a older date has been chosen
|
||||||
|
* https://github.com/symfony/symfony/pull/6471#discussion_r2527156
|
||||||
|
*/
|
||||||
|
$value = 'Sat, 01 Jan 00 00:00:00 +0000';
|
||||||
|
}
|
||||||
|
|
||||||
if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
|
if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
|
||||||
throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
|
throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
|
||||||
}
|
}
|
||||||
|
@ -693,6 +693,10 @@ class Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->getExpires()) {
|
if (null !== $this->getExpires()) {
|
||||||
|
if (!$this->getExpires() instanceof \DateTime) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getExpires()->format('U') - $this->getDate()->format('U');
|
return $this->getExpires()->format('U') - $this->getDate()->format('U');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +164,11 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
|
|||||||
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
|
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
|
||||||
$this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');
|
$this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$response->headers->set('Cache-Control', 'must-revalidate');
|
||||||
|
$response->headers->set('Expires', -1);
|
||||||
|
$this->assertEquals('Sat, 01 Jan 00 00:00:00 +0000', $response->getExpires()->format(DATE_RFC822));
|
||||||
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available');
|
$this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available');
|
||||||
}
|
}
|
||||||
@ -214,6 +219,11 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
|
|||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->expire();
|
$response->expire();
|
||||||
$this->assertFalse($response->headers->has('Age'), '->expire() does nothing when the response does not include freshness information');
|
$this->assertFalse($response->headers->has('Age'), '->expire() does nothing when the response does not include freshness information');
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$response->headers->set('Expires', -1);
|
||||||
|
$response->expire();
|
||||||
|
$this->assertEquals(0, $response->headers->get('Age'), '->expire() does not set the Age to 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetTtl()
|
public function testGetTtl()
|
||||||
|
Reference in New Issue
Block a user