/** * Retrieve all identities from blocks for further cache invalidation * * @param \Magento\Framework\View\Layout $subject * @param mixed $result * @return mixed */ public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result) { if ($subject->isCacheable() && $this->config->isEnabled()) { $tags = []; foreach ($subject->getAllBlocks() as $block) { if ($block instanceof \Magento\Framework\DataObject\IdentityInterface) { $isEsiBlock = $block->getTtl() > 0; $isVarnish = $this->config->getType() == \Magento\PageCache\Model\Config::VARNISH; if ($isVarnish && $isEsiBlock) { continue; } $tags = array_merge($tags, $block->getIdentities()); } } $tags = array_unique($tags); $this->response->setHeader('X-Magento-Tags', implode(',', $tags)); } return $result; }
/** * @param ResponseInterface $response * @return $this */ protected function applyHttpHeaders(ResponseInterface $response) { if (!empty($this->httpResponseCode)) { $response->setHttpResponseCode($this->httpResponseCode); } if ($this->statusHeaderCode) { $response->setStatusHeader($this->statusHeaderCode, $this->statusHeaderVersion, $this->statusHeaderPhrase); } if (!empty($this->headers)) { foreach ($this->headers as $headerData) { $response->setHeader($headerData['name'], $headerData['value'], $headerData['replace']); } } return $this; }
/** * Set "auth failed" headers to the specified response object * * @param string $realm * @return void */ public function setAuthenticationFailed($realm) { $this->response->setHeader('HTTP/1.1', '401 Unauthorized')->setHeader('WWW-Authenticate', 'Basic realm="' . $realm . '"')->setBody('<h1>401 Unauthorized</h1>'); }
/** * Setting headers to response for sending empty rss * * @param \Magento\Framework\App\ResponseInterface $response * @return void */ public function sendEmptyRssFeed(\Magento\Framework\App\ResponseInterface $response) { $response->setHeader('HTTP/1.1', '404 Not Found')->setHeader('Status', '404 File not found')->setHeader('Content-Type', 'text/plain; charset=UTF-8')->setBody(__('There was no RSS feed enabled.')); }