mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
@ -295,7 +295,7 @@ class PageCache extends ActionFilter implements DynamicContentAwareInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$all = $response->headers->toArray(true);
|
$all = $response->headers->toOriginalArray();
|
||||||
if (is_array($this->cacheHeaders)) {
|
if (is_array($this->cacheHeaders)) {
|
||||||
$filtered = [];
|
$filtered = [];
|
||||||
foreach ($this->cacheHeaders as $name) {
|
foreach ($this->cacheHeaders as $name) {
|
||||||
|
@ -177,15 +177,20 @@ class HeaderCollection extends BaseObject implements \IteratorAggregate, \ArrayA
|
|||||||
* Returns the collection as a PHP array.
|
* Returns the collection as a PHP array.
|
||||||
* @return array the array representation of the collection.
|
* @return array the array representation of the collection.
|
||||||
* The array keys are header names, and the array values are the corresponding header values.
|
* 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 \array_map(function ($normalizedName) {
|
||||||
return $this->_headers[$normalizedName];
|
return $this->_headers[$normalizedName];
|
||||||
}, \array_flip($this->_originalHeaderNames));
|
}, \array_flip($this->_originalHeaderNames));
|
||||||
|
@ -243,7 +243,7 @@ class PageCacheTest extends TestCase
|
|||||||
}
|
}
|
||||||
// Headers
|
// Headers
|
||||||
if (isset($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) {
|
foreach ($testCase['headers'] as $name => $expected) {
|
||||||
$this->assertSame($expected, Yii::$app->response->headers->has($name), $testCase['name']);
|
$this->assertSame($expected, Yii::$app->response->headers->has($name), $testCase['name']);
|
||||||
if ($expected) {
|
if ($expected) {
|
||||||
|
@ -43,14 +43,14 @@ class HeaderCollectionTest extends TestCase
|
|||||||
$this->assertSame('1', $headerCollection->get('x-hEadER'));
|
$this->assertSame('1', $headerCollection->get('x-hEadER'));
|
||||||
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
|
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
|
||||||
$this->assertSame(['x-header' => ['1']], $headerCollection->toArray());
|
$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');
|
$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('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());
|
||||||
$this->assertSame(['X-HEADER' => ['2']], $headerCollection->toArray(true));
|
$this->assertSame(['X-HEADER' => ['2']], $headerCollection->toOriginalArray());
|
||||||
|
|
||||||
$headerCollection->offsetSet('X-HEADER', '3');
|
$headerCollection->offsetSet('X-HEADER', '3');
|
||||||
$this->assertSame('3', $headerCollection->get('X-Header'));
|
$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'));
|
||||||
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
|
$this->assertSame(['1'], $headerCollection->get('x-hEadER', null, false));
|
||||||
$this->assertSame(['x-header' => ['1']], $headerCollection->toArray());
|
$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');
|
$headerCollection->add('X-HEADER', '2');
|
||||||
$this->assertSame('1', $headerCollection->get('X-Header'));
|
$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', $headerCollection->get('x-hEadER'));
|
||||||
$this->assertSame(['1', '2'], $headerCollection->get('x-header', null, false));
|
$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());
|
||||||
$this->assertSame(['X-Header' => ['1', '2']], $headerCollection->toArray(true));
|
$this->assertSame(['X-Header' => ['1', '2']], $headerCollection->toOriginalArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemover()
|
public function testRemover()
|
||||||
|
Reference in New Issue
Block a user