public function testIsSecure() { foreach ($this->secureTests as $cookieStr) { $cookie = Zend_Http_Cookie::factory($cookieStr); $this->assertTrue($cookie->isSecure()); } foreach ($this->nonSecureTests as $cookieStr) { $cookie = Zend_Http_Cookie::factory($cookieStr); $this->assertFalse($cookie->isSecure()); } }
/** * Add a cookie to the jar. Cookie should be passed either as a Zend_Http_Cookie object * or as a string - in which case an object is created from the string. * * @param Zend_Http_Cookie|string $cookie * @param Zend_Uri_Http|string $red_uri Optional reference URI (for domain, path, secure) */ public function addCookie($cookie, $ref_uri = null) { if (is_string($cookie)) { $cookie = Zend_Http_Cookie::factory($cookie, $ref_uri); } if ($cookie instanceof Zend_Http_Cookie) { $domain = $cookie->getDomain(); $path = $cookie->getPath(); if (!isset($this->cookies[$domain])) { $this->cookies[$domain] = array(); } if (!isset($this->cookies[$domain][$path])) { $this->cookies[$domain][$path] = array(); } $this->cookies[$domain][$path][$cookie->getName()] = $cookie; } else { throw new Zend_Http_Exception('Supplient argument is not a valid cookie string or object'); } }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. */ public function setCookie($cookie, $value = null) { if (!is_null($value)) { $value = urlencode($value); } if (isset($this->Cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->Cookiejar->addCookie($cookie); } elseif (is_string($cookie) && !is_null($value)) { if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { throw new Zend_Http_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$name})"); } $cookie = Zend_Http_Cookie::factory("{$cookie}={$value}", $this->uri); $this->Cookiejar->addCookie($cookie); } } else { parent::setCookie($cookie, $value); } }
/** * Add a cookie to the request. If the client has no Cookie Jar, the cookies * will be added directly to the headers array as "Cookie" headers. * * @param Zend_Http_Cookie|string $cookie * @param string|null $value If "cookie" is a string, this is the cookie value. * @return Zend_Http_Client */ public function setCookie($cookie, $value = null) { if ($value !== null) { $value = urlencode($value); } if (isset($this->Cookiejar)) { if ($cookie instanceof Zend_Http_Cookie) { $this->Cookiejar->addCookie($cookie); } elseif (is_string($cookie) && $value !== null) { $cookie = Zend_Http_Cookie::factory("{$cookie}={$value}", $this->uri); $this->Cookiejar->addCookie($cookie); } } else { if ($cookie instanceof Zend_Http_Cookie) { $cookie = $cookie->getName(); $value = $cookie->getValue(); } if (preg_match("/[=,; \t\r\n\v\f]/", $cookie)) { throw new Zend_Http_Client_Exception("Cookie name cannot contain these characters: =,; \t\r\n\v\f ({$name})"); } $value = urlencode($value); $this->setHeaders('cookie', "{$cookie}={$value}", false); } return $this; }