Skip to content

Commit d76b484

Browse files
committed
LYNX-232: Fixed FPC cache header setting
1 parent 7834423 commit d76b484

File tree

1 file changed

+19
-14
lines changed
  • app/code/Magento/GraphQlCache/Controller/Plugin

1 file changed

+19
-14
lines changed

app/code/Magento/GraphQlCache/Controller/Plugin/GraphQl.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
use Magento\Framework\App\FrontControllerInterface;
1111
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\App\Response\Http as ResponseHttp;
1213
use Magento\Framework\App\ResponseInterface;
14+
use Magento\Framework\Controller\ResultInterface;
1315
use Magento\Framework\Registry;
1416
use Magento\GraphQl\Controller\HttpRequestProcessor;
1517
use Magento\GraphQlCache\Model\CacheableQuery;
@@ -53,6 +55,11 @@ class GraphQl
5355
*/
5456
private $logger;
5557

58+
/**
59+
* @var RequestInterface
60+
*/
61+
private $request;
62+
5663
/**
5764
* @param CacheableQuery $cacheableQuery
5865
* @param CacheIdCalculator $cacheIdCalculator
@@ -96,26 +103,24 @@ public function beforeDispatch(
96103
}
97104
/** @var \Magento\Framework\App\Request\Http $request */
98105
$this->requestProcessor->processHeaders($request);
106+
$this->request = $request;
99107
}
100108

101109
/**
102-
* Set cache headers after dispatch
110+
* Plugin for GraphQL after render from dispatch to set tag and cache headers
103111
*
104-
* @param FrontControllerInterface $subject
105-
* @param ResponseInterface $response
106-
* @param RequestInterface $request
107-
* @return ResponseInterface
112+
* @param ResultInterface $subject
113+
* @param ResultInterface $result
114+
* @param ResponseHttp $response
115+
* @return ResultInterface
108116
*
109117
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
110118
*/
111-
public function afterDispatch(
112-
FrontControllerInterface $subject,
113-
$response,
114-
RequestInterface $request
115-
) {
116-
if (!$this->config->isEnabled() || str_contains($request->getContent(), 'mutation')) {
119+
public function afterRenderResult(ResultInterface $subject, ResultInterface $result, ResponseHttp $response)
120+
{
121+
if (!$this->config->isEnabled() || $this->request && str_contains($this->request->getContent(), 'mutation')) {
117122
$response->setNoCacheHeaders();
118-
return $response;
123+
return $result;
119124
}
120125

121126
/** @see \Magento\Framework\App\Http::launch */
@@ -128,12 +133,12 @@ public function afterDispatch(
128133
}
129134
if (!$this->cacheableQuery->shouldPopulateCacheHeadersWithTags()) {
130135
$response->setNoCacheHeaders();
131-
return $response;
136+
return $result;
132137
}
133138

134139
$response->setPublicHeaders($this->config->getTtl());
135140
$response->setHeader('X-Magento-Tags', implode(',', $this->cacheableQuery->getCacheTags()), true);
136141

137-
return $response;
142+
return $result;
138143
}
139144
}

0 commit comments

Comments
 (0)