Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add x-magento-cache-debug header for production mode use build-in cache #39735

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
namespace Magento\PageCache\Model\App\FrontController;

use Magento\Framework\App\PageCache\NotCacheableInterface;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\App\State;

/**
* Plugin for processing builtin cache
Expand Down Expand Up @@ -111,7 +112,7 @@ protected function addDebugHeaders(ResponseHttp $result)
*/
protected function addDebugHeader(ResponseHttp $response, $name, $value, $replace = false)
{
if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
if ($name == 'X-Magento-Cache-Debug' || $this->state->getMode() == State::MODE_DEVELOPER) {
$response->setHeader($name, $value, $replace);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
namespace Magento\PageCache\Model\Controller\Result;

use Magento\PageCache\Model\Config;
use Laminas\Http\Header\HeaderInterface as HttpHeaderInterface;
use Magento\Framework\App\PageCache\Kernel;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\App\State as AppState;
use Magento\Framework\Registry;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Laminas\Http\Header\HeaderInterface as HttpHeaderInterface;
use Magento\Framework\Registry;
use Magento\PageCache\Model\Cache\Type as CacheType;
use Magento\PageCache\Model\Config;

/**
* Plugin for processing builtin cache
Expand Down Expand Up @@ -79,9 +79,8 @@ public function afterRenderResult(ResultInterface $subject, ResultInterface $res
if ($cacheControlHeader instanceof HttpHeaderInterface) {
$response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
}

$response->setHeader('X-Magento-Cache-Debug', 'MISS', true);
}
$response->setHeader('X-Magento-Cache-Debug', 'MISS', true);

$tagsHeader = $response->getHeader('X-Magento-Tags');
$tags = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -130,8 +130,15 @@ function ($arg1, $arg2 = null, $arg3 = null) {
}
);
} else {
$this->responseMock->expects($this->never())
->method('setHeader');
$this->responseMock
->method('setHeader')
->willReturnCallback(
function ($arg1, $arg2 = null, $arg3 = null) {
if ($arg1 === 'X-Magento-Cache-Debug' && $arg2 === 'MISS' && $arg3 === true) {
return null;
}
}
);
}
$this->responseMock
->expects($this->once())
Expand Down Expand Up @@ -208,14 +215,11 @@ public function testAroundDispatchReturnsCache($state): void
$this->stateMock->expects($this->any())
->method('getMode')
->willReturn($state);
if ($state == State::MODE_DEVELOPER) {
$this->responseMock->expects($this->once())
->method('setHeader')
->with('X-Magento-Cache-Debug');
} else {
$this->responseMock->expects($this->never())
->method('setHeader');
}

$this->responseMock->expects($this->once())
->method('setHeader')
->with('X-Magento-Cache-Debug');

$this->assertSame(
$this->responseMock,
$this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -150,9 +150,15 @@ public function testAfterResultWithPlugin()
$this->responseMock->expects(static::once())
->method('clearHeader')
->with('X-Magento-Tags');
$this->responseMock->expects(static::once())
$this->responseMock->expects(static::any())
->method('setHeader')
->with('X-Magento-Tags', 'tag,' . CacheType::CACHE_TAG);
->willReturnCallback(function ($arg1, $arg2 = null, $arg3 = null) {
if ($arg1 === 'X-Magento-Cache-Debug' && $arg2 === 'MISS' && $arg3 === true) {
return null;
} elseif ($arg1 === 'X-Magento-Tags' && $arg2 === 'tag,' . CacheType::CACHE_TAG) {
return null;
}
});
$this->kernelMock->expects(static::once())
->method('process')
->with($this->responseMock);
Expand Down