Автор: Fabien Potencier (fabien@symfony.com)
 /**
  * Parse the standard `Header-name: value' headers into
  * individual header name/value pairs
  *
  * @param string $header
  */
 private function parseHeader($header)
 {
     if (empty($header)) {
         return;
     }
     $pos = strpos($header, ": ");
     if (false !== $pos) {
         $name = trim(substr($header, 0, $pos));
         $value = substr($header, $pos + 2);
         if (strtolower($name) == "set-cookie") {
             $cookie = CookieParser::fromString($value);
             $this->cookies[] = new Cookie($cookie->getName(), $cookie->getRawValue(), (int) $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
         } else {
             $this->headers[$name] = $value;
         }
     }
 }
Пример #2
3
 public function testIsExpired()
 {
     $cookie = new Cookie('foo', 'bar');
     $this->assertFalse($cookie->isExpired(), '->isExpired() returns false when the cookie never expires (null as expires time)');
     $cookie = new Cookie('foo', 'bar', time() - 86400);
     $this->assertTrue($cookie->isExpired(), '->isExpired() returns true when the cookie is expired');
     $cookie = new Cookie('foo', 'bar', 0);
     $this->assertFalse($cookie->isExpired());
 }
Пример #3
2
 /**
  * {@inheritdoc}
  */
 public function updateFromResponse(Response $response, $uri = null)
 {
     foreach ($response->getHeader('Set-Cookie', false) as $cookie) {
         $this->set(Cookie::fromString(urldecode($cookie), $uri));
     }
 }