Browse Source

Fix BC introduced in #19188 (#19194)

tags/2.0.45
Bizley 3 years ago committed by GitHub
parent
commit
60c91eb433
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      framework/filters/PageCache.php
  2. 17
      framework/web/HeaderCollection.php
  3. 2
      tests/framework/filters/PageCacheTest.php
  4. 8
      tests/framework/web/HeaderCollectionTest.php

2
framework/filters/PageCache.php

@ -295,7 +295,7 @@ class PageCache extends ActionFilter implements DynamicContentAwareInterface
return;
}
$all = $response->headers->toArray(true);
$all = $response->headers->toOriginalArray();
if (is_array($this->cacheHeaders)) {
$filtered = [];
foreach ($this->cacheHeaders as $name) {

17
framework/web/HeaderCollection.php

@ -177,15 +177,20 @@ class HeaderCollection extends BaseObject implements \IteratorAggregate, \ArrayA
* Returns the collection as a PHP array.
* @return array the array representation of the collection.
* The array keys are header names, and the array values are the corresponding header values.
* Since 2.0.45 you can pass true here to get the headers list of original header names (case-sensitive) instead of
* default normalized (case-insensitive) ones.
*/
public function toArray($originalNames = false)
public function toArray()
{
if ($originalNames === false) {
return $this->_headers;
}
return $this->_headers;
}
/**
* Returns the collection as a PHP array but instead of using normalized header names as keys (like [[toArray()]])
* it uses original header names (case-sensitive).
* @return array the array representation of the collection.
* @since 2.0.45
*/
public function toOriginalArray()
{
return \array_map(function ($normalizedName) {
return $this->_headers[$normalizedName];
}, \array_flip($this->_originalHeaderNames));

2
tests/framework/filters/PageCacheTest.php

@ -243,7 +243,7 @@ class PageCacheTest extends TestCase
}
// Headers
if (isset($testCase['headers'])) {
$headersExpected = Yii::$app->response->headers->toArray(true);
$headersExpected = Yii::$app->response->headers->toOriginalArray();
foreach ($testCase['headers'] as $name => $expected) {
$this->assertSame($expected, Yii::$app->response->headers->has($name), $testCase['name']);
if ($expected) {

8
tests/framework/web/HeaderCollectionTest.php

@ -43,14 +43,14 @@ class HeaderCollectionTest extends TestCase
$this->assertSame('1', $headerCollection->get('x-hEadER'));
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
$this->assertSame(['x-header' => ['1']], $headerCollection->toArray());
$this->assertSame(['X-Header' => ['1']], $headerCollection->toArray(true));
$this->assertSame(['X-Header' => ['1']], $headerCollection->toOriginalArray());
$headerCollection->set('X-HEADER', '2');
$this->assertSame('2', $headerCollection->get('X-Header'));
$this->assertSame('2', $headerCollection->get('x-header'));
$this->assertSame('2', $headerCollection->get('x-hEadER'));
$this->assertSame(['x-header' => ['2']], $headerCollection->toArray());
$this->assertSame(['X-HEADER' => ['2']], $headerCollection->toArray(true));
$this->assertSame(['X-HEADER' => ['2']], $headerCollection->toOriginalArray());
$headerCollection->offsetSet('X-HEADER', '3');
$this->assertSame('3', $headerCollection->get('X-Header'));
@ -77,7 +77,7 @@ class HeaderCollectionTest extends TestCase
$this->assertSame('1', $headerCollection->get('x-hEadER'));
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
$this->assertSame(['x-header' => ['1']], $headerCollection->toArray());
$this->assertSame(['X-Header' => ['1']], $headerCollection->toArray(true));
$this->assertSame(['X-Header' => ['1']], $headerCollection->toOriginalArray());
$headerCollection->add('X-HEADER', '2');
$this->assertSame('1', $headerCollection->get('X-Header'));
@ -85,7 +85,7 @@ class HeaderCollectionTest extends TestCase
$this->assertSame('1', $headerCollection->get('x-hEadER'));
$this->assertSame(['1', '2'], $headerCollection->get('x-header', null, false));
$this->assertSame(['x-header' => ['1', '2']], $headerCollection->toArray());
$this->assertSame(['X-Header' => ['1', '2']], $headerCollection->toArray(true));
$this->assertSame(['X-Header' => ['1', '2']], $headerCollection->toOriginalArray());
}
public function testRemover()

Loading…
Cancel
Save