From b833b32c023e2dec7b7298d663ddb869eac26206 Mon Sep 17 00:00:00 2001 From: Bizley Date: Thu, 27 Jan 2022 14:15:48 +0100 Subject: [PATCH 1/2] Fixes introduced BC --- framework/filters/PageCache.php | 2 +- framework/web/HeaderCollection.php | 17 +++++++++++------ tests/framework/web/HeaderCollectionTest.php | 8 ++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/framework/filters/PageCache.php b/framework/filters/PageCache.php index f02bf2f3826..46a8d22e53f 100644 --- a/framework/filters/PageCache.php +++ b/framework/filters/PageCache.php @@ -295,7 +295,7 @@ private function insertResponseHeaderCollectionIntoData(Response $response, arra return; } - $all = $response->headers->toArray(true); + $all = $response->headers->toOriginalArray(); if (is_array($this->cacheHeaders)) { $filtered = []; foreach ($this->cacheHeaders as $name) { diff --git a/framework/web/HeaderCollection.php b/framework/web/HeaderCollection.php index 68ac2e9fbf5..eb7059b7efb 100644 --- a/framework/web/HeaderCollection.php +++ b/framework/web/HeaderCollection.php @@ -177,15 +177,20 @@ public function removeAll() * 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)); diff --git a/tests/framework/web/HeaderCollectionTest.php b/tests/framework/web/HeaderCollectionTest.php index 9569ba3f3ab..33331e7cc02 100644 --- a/tests/framework/web/HeaderCollectionTest.php +++ b/tests/framework/web/HeaderCollectionTest.php @@ -43,14 +43,14 @@ public function testSetter() $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 @@ public function testAdder() $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 @@ public function testAdder() $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() From 46481ff745ce91cfe9a9e85f14043eb1e39e43a7 Mon Sep 17 00:00:00 2001 From: Bizley Date: Thu, 27 Jan 2022 14:34:50 +0100 Subject: [PATCH 2/2] Updated last one --- tests/framework/filters/PageCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/framework/filters/PageCacheTest.php b/tests/framework/filters/PageCacheTest.php index 1f0896f65ba..3b06411f67c 100644 --- a/tests/framework/filters/PageCacheTest.php +++ b/tests/framework/filters/PageCacheTest.php @@ -243,7 +243,7 @@ public function testCache($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) {