Exemplo n.º 1
0
 /**
  * Test setting body in JSON format
  */
 public function testRepresentJson()
 {
     $this->model->setHeader('Content-Type', 'text/javascript');
     $this->model->representJson('json_string');
     $this->assertEquals('application/json', $this->model->getHeader('Content-Type')->getFieldValue());
     $this->assertEquals('json_string', $this->model->getBody('default'));
 }
Exemplo n.º 2
0
 /**
  * Set cache control
  *
  * @param ResponseHttp $result
  * @return ResponseHttp
  */
 protected function addDebugHeaders(ResponseHttp $result)
 {
     $cacheControl = $result->getHeader('Cache-Control')->getFieldValue();
     $this->addDebugHeader($result, 'X-Magento-Cache-Control', $cacheControl);
     $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'MISS', true);
     return $result;
 }
Exemplo n.º 3
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')['value'], $matches)) {
         $maxAge = $matches[1];
         $response->setNoCacheHeaders();
         if ($response->getHttpResponseCode() == 200 && ($this->request->isGet() || $this->request->isHead())) {
             $tagsHeader = $response->getHeader('X-Magento-Tags');
             $tags = $tagsHeader ? explode(',', $tagsHeader['value']) : array();
             $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);
         }
     }
 }
 /**
  * Set cache control
  *
  * @param ResponseHttp $result
  * @return ResponseHttp
  */
 protected function addDebugHeaders(ResponseHttp $result)
 {
     $cacheControlHeader = $result->getHeader('Cache-Control');
     if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) {
         $this->addDebugHeader($result, 'X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
     }
     $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'MISS', true);
     return $result;
 }
Exemplo n.º 5
0
 public function testSetXFrameOptions()
 {
     $value = 'DENY';
     $this->model->setXFrameOptions($value);
     $this->assertSame($value, $this->model->getHeader(Http::HEADER_X_FRAME_OPT)->getFieldValue());
 }
Exemplo n.º 6
0
 /**
  * Test for getHeader method. Validation for attempt to get not existing header
  *
  * @covers \Magento\Framework\App\Response\Http::getHeader
  */
 public function testGetHeaderNotExists()
 {
     $this->model->setHeader('Name', 'value', true);
     $this->assertFalse($this->model->getHeader('Wrong name'));
 }
 protected function assertHeaderNotPresent($name)
 {
     $this->interceptedResponse->sendResponse();
     $this->assertFalse($this->interceptedResponse->getHeader($name));
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getHeader($name)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getHeader');
     if (!$pluginInfo) {
         return parent::getHeader($name);
     } else {
         return $this->___callPlugins('getHeader', func_get_args(), $pluginInfo);
     }
 }