Exemple #1
0
 /**
  * Modify and cache application response
  *
  * @param \Magento\Framework\App\Response\Http $response
  * @return void
  */
 public function process(\Magento\Framework\App\Response\Http $response)
 {
     if (preg_match('/public.*s-maxage=(\\d+)/', $response->getHeader('Cache-Control')->getFieldValue(), $matches)) {
         $maxAge = $matches[1];
         $response->setNoCacheHeaders();
         if (($response->getHttpResponseCode() == 200 || $response->getHttpResponseCode() == 404) && ($this->request->isGet() || $this->request->isHead())) {
             $tagsHeader = $response->getHeader('X-Magento-Tags');
             $tags = $tagsHeader ? explode(',', $tagsHeader->getFieldValue()) : [];
             $response->clearHeader('Set-Cookie');
             $response->clearHeader('X-Magento-Tags');
             if (!headers_sent()) {
                 header_remove('Set-Cookie');
             }
             $this->cache->save(serialize($response), $this->identifier->getValue(), $tags, $maxAge);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getHttpResponseCode()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getHttpResponseCode');
     if (!$pluginInfo) {
         return parent::getHttpResponseCode();
     } else {
         return $this->___callPlugins('getHttpResponseCode', func_get_args(), $pluginInfo);
     }
 }