diff --git a/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php b/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php index fd04f1fe4ca2fbe28854f837b0a3323d70164473..d86d8df059161ffdf7b0b04bfde642c328a3a02f 100644 --- a/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php +++ b/app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php @@ -76,6 +76,11 @@ class BuiltinPlugin $this->kernel->process($result); } } else { + json_decode($result->getContent()); + if (json_last_error() == JSON_ERROR_NONE) { + // reset profiler to avoid appending profiling stat to JSON response + \Magento\Framework\Profiler::reset(); + } $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true); } return $result; diff --git a/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php b/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php index 9e4102c889052f63cf2f358577d5059fa7aebc51..ae38b76db495f0e4fefbc1dd3763516ba55d0ef0 100644 --- a/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php +++ b/app/code/Magento/PageCache/Test/Unit/Model/App/FrontController/BuiltinPluginTest.php @@ -200,6 +200,7 @@ class BuiltinPluginTest extends \PHPUnit_Framework_TestCase $this->responseMock->expects($this->never()) ->method('setHeader'); } + $this->responseMock->expects($this->once())->method('getContent'); $this->assertSame( $this->responseMock, $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock) diff --git a/lib/internal/Magento/Framework/Controller/Result/Json.php b/lib/internal/Magento/Framework/Controller/Result/Json.php index f1d480efec72e9ec8b610e4209bb581cbf1cb773..bc3855448ccc264e16b34f061518a3e0507998cd 100644 --- a/lib/internal/Magento/Framework/Controller/Result/Json.php +++ b/lib/internal/Magento/Framework/Controller/Result/Json.php @@ -63,6 +63,8 @@ class Json extends AbstractResult */ protected function render(ResponseInterface $response) { + // reset profiler to avoid appending profiling stat to JSON response + \Magento\Framework\Profiler::reset(); $this->translateInline->processResponseBody($this->json, true); $response->representJson($this->json); return $this;