bug #10382 10158 get vary multiple (bbinkovitz)
This PR was squashed before being merged into the 2.3 branch (closes #10382).
Discussion
----------
10158 get vary multiple
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | [#10158]
| License | MIT
| Doc PR | none
Commits
-------
3a4a3cb
10158 get vary multiple
This commit is contained in:
commit
b6a6791f97
@ -987,11 +987,17 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function getVary()
|
public function getVary()
|
||||||
{
|
{
|
||||||
if (!$vary = $this->headers->get('Vary')) {
|
if (!$vary = $this->headers->get('Vary', null, false)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_array($vary) ? $vary : preg_split('/[\s,]+/', $vary);
|
|
||||||
|
$ret = array();
|
||||||
|
foreach ($vary as $item) {
|
||||||
|
$ret = array_merge($ret, preg_split('/[\s,]+/', $item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -284,6 +284,16 @@ class ResponseTest extends ResponseTestCase
|
|||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->headers->set('Vary', 'Accept-Language,User-Agent, X-Foo');
|
$response->headers->set('Vary', 'Accept-Language,User-Agent, X-Foo');
|
||||||
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by commas');
|
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by commas');
|
||||||
|
|
||||||
|
$response = new Response();
|
||||||
|
$vary = array(
|
||||||
|
'Accept-Language',
|
||||||
|
'User-Agent',
|
||||||
|
'X-foo',
|
||||||
|
);
|
||||||
|
$response->headers->set('Vary', $vary);
|
||||||
|
$this->assertEquals($response->headers->get('Vary', NULL, FALSE) , $response->getVary(), '->getVary() parses multiple header name values in arrays');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetVary()
|
public function testSetVary()
|
||||||
@ -296,7 +306,9 @@ class ResponseTest extends ResponseTestCase
|
|||||||
$this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() replace the vary header by default');
|
$this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() replace the vary header by default');
|
||||||
|
|
||||||
$response->setVary('X-Foo', false);
|
$response->setVary('X-Foo', false);
|
||||||
$this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() doesn\'t change the Vary header if replace is set to false');
|
$this->assertTrue(in_array('Accept-Language', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
|
||||||
|
$this->assertTrue(in_array('User-Agent', $response->getVary()), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
|
||||||
|
$this->assertTrue(in_array('X-Foo', $response->getVary()), '->setVary() adds new Vary headers when replace is set to false');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefaultContentType()
|
public function testDefaultContentType()
|
||||||
|
Reference in New Issue
Block a user