Skip to content

Commit

Permalink
[Http] Adding a fix for parsing the Cache-Control directives of a mes…
Browse files Browse the repository at this point in the history
…sage that has multiple Cache-Control headers. Closes #2.
  • Loading branch information
mtdowling committed Apr 21, 2011
1 parent a1baf54 commit 88bcaa8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Guzzle/Http/Message/AbstractMessage.php
Expand Up @@ -239,6 +239,9 @@ protected function parseCacheControlDirective()
$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;
Expand Down
10 changes: 10 additions & 0 deletions tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php
Expand Up @@ -133,5 +133,15 @@ public function testHoldsCacheControlDirectives()
$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'));
}
}

0 comments on commit 88bcaa8

Please sign in to comment.