mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 01:53:58 +01:00
[Http] Adding a fix for parsing the Cache-Control directives of a message that has multiple Cache-Control headers. Closes #2.
This commit is contained in:
parent
a1baf54de7
commit
88bcaa8390
@ -239,6 +239,9 @@ abstract class AbstractMessage implements MessageInterface
|
||||
$this->cacheControl = array();
|
||||
$cacheControl = $this->getHeader('Cache-Control');
|
||||
if ($cacheControl) {
|
||||
if (is_array($cacheControl)) {
|
||||
$cacheControl = implode(',', $cacheControl);
|
||||
}
|
||||
foreach (explode(',', $cacheControl) as $pieces) {
|
||||
$parts = array_map('trim', explode('=', $pieces));
|
||||
$this->cacheControl[$parts[0]] = isset($parts[1]) ? $parts[1] : true;
|
||||
|
@ -133,5 +133,15 @@ class AbstractMessageTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$this->assertFalse($r->hasCacheControlDirective('max-age'));
|
||||
$r->addCacheControlDirective('must-revalidate');
|
||||
$this->assertTrue($r->hasCacheControlDirective('must-revalidate'));
|
||||
|
||||
// Make sure that it works with multiple Cache-Control headers
|
||||
$r->setHeader('Cache-Control', 'must-revalidate, max-age=100');
|
||||
$r->addHeaders(array(
|
||||
'Cache-Control' => 'no-cache'
|
||||
));
|
||||
|
||||
$this->assertEquals(true, $r->getCacheControlDirective('no-cache'));
|
||||
$this->assertEquals(true, $r->getCacheControlDirective('must-revalidate'));
|
||||
$this->assertEquals(100, $r->getCacheControlDirective('max-age'));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user