コード例 #1
0
ファイル: Response.php プロジェクト: NicolasBadey/symfony
 protected function fixContentType()
 {
     if (!$this->headers->has('Content-Type')) {
         $this->headers->set('Content-Type', 'text/html; charset=' . $this->charset);
     } elseif ('text/' === substr($this->headers->get('Content-Type'), 0, 5) && false === strpos($this->headers->get('Content-Type'), 'charset')) {
         // add the charset
         $this->headers->set('Content-Type', $this->headers->get('Content-Type') . '; charset=' . $this->charset);
     }
 }
コード例 #2
0
ファイル: Response.php プロジェクト: mitap45/Daily
 /**
  * Returns true if the response must be revalidated by caches.
  *
  * This method indicates that the response must not be served stale by a
  * cache in any circumstance without first revalidating with the origin.
  * When present, the TTL of the response should not be overridden to be
  * greater than the value provided by the origin.
  *
  * @return bool true if the response must be revalidated by a cache, false otherwise
  *
  * @api
  */
 public function mustRevalidate()
 {
     return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('proxy-revalidate');
 }
コード例 #3
0
 /**
  * Returns true if the response includes headers that can be used to validate
  * the response with the origin server using a conditional GET request.
  *
  * @return bool true if the response is validateable, false otherwise
  */
 public function isValidateable()
 {
     return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
 }
コード例 #4
0
ファイル: Response.php プロジェクト: cilefen/symfony
 /**
  * Returns the Date header as a DateTime instance.
  *
  * @return \DateTime A \DateTime instance
  *
  * @throws \RuntimeException When the header is not parseable
  */
 public function getDate()
 {
     if (!$this->headers->has('Date')) {
         $this->setDate(\DateTime::createFromFormat('U', time()));
     }
     return $this->headers->getDate('Date');
 }
コード例 #5
0
ファイル: Response.php プロジェクト: pierreleplatois/sialab
 /**
  * Returns the Date header as a DateTime instance.
  *
  * @return \DateTime A \DateTime instance
  *
  * @throws \RuntimeException When the header is not parseable
  *
  * @api
  */
 public function getDate()
 {
     if (!$this->headers->has('Date')) {
         $this->setDate(new \DateTime());
     }
     return $this->headers->getDate('Date');
 }
コード例 #6
0
    public function testRemoveCookie()
    {
        $bag = new ResponseHeaderBag();
        $this->assertFalse($bag->has('set-cookie'));

        $bag->setCookie(new Cookie('foo', 'bar', 0, '/path/foo', 'foo.bar'));
        $bag->setCookie(new Cookie('bar', 'foo', 0, '/path/bar', 'foo.bar'));
        $this->assertTrue($bag->has('set-cookie'));

        $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
        $this->assertTrue(isset($cookies['foo.bar']['/path/foo']));

        $bag->removeCookie('foo', '/path/foo', 'foo.bar');
        $this->assertTrue($bag->has('set-cookie'));

        $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
        $this->assertFalse(isset($cookies['foo.bar']['/path/foo']));

        $bag->removeCookie('bar', '/path/bar', 'foo.bar');
        $this->assertFalse($bag->has('set-cookie'));

        $cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
        $this->assertFalse(isset($cookies['foo.bar']));
    }