bug #14635 [HttpKernel] Handle an array vary header in the http cache store (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpKernel] Handle an array vary header in the http cache store

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12118
| License       | MIT
| Doc PR        | -

Commits
-------

5930800 [HttpKernel] Handle an array vary header in the http cache store
This commit is contained in:
Fabien Potencier 2015-05-21 06:26:25 +02:00
commit 438d394a1c
2 changed files with 11 additions and 1 deletions

View File

@ -127,7 +127,7 @@ class Store implements StoreInterface
// find a cached entry that matches the request.
$match = null;
foreach ($entries as $entry) {
if ($this->requestsMatch(isset($entry[1]['vary'][0]) ? $entry[1]['vary'][0] : '', $request->headers->all(), $entry[0])) {
if ($this->requestsMatch(isset($entry[1]['vary'][0]) ? implode(', ', $entry[1]['vary']) : '', $request->headers->all(), $entry[0])) {
$match = $entry;
break;

View File

@ -168,6 +168,16 @@ class StoreTest extends \PHPUnit_Framework_TestCase
$this->assertNull($this->store->lookup($req2));
}
public function testDoesNotReturnEntriesThatSlightlyVaryWithLookup()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bam'));
$res = new Response('test', 200, array('Vary' => array('Foo', 'Bar')));
$this->store->write($req1, $res);
$this->assertNull($this->store->lookup($req2));
}
public function testStoresMultipleResponsesForEachVaryCombination()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));