Permalink
Browse files

If a cookie already exists and the server asks to set it again with a…

… null value, the cookie must be deleted.
  • Loading branch information...
unixo committed Jan 31, 2014
1 parent dce090b commit f9a2553d8ed0526b56d170a4f5f8434c4daa829e
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php
@@ -85,6 +85,28 @@ public function all($domain = null, $path = null, $name = null, $skipDiscardable
}));
}
/**
* If a cookie already exists and the server asks to set it again with a null value, the
* cookie must be deleted.
*
* @param \Guzzle\Plugin\Cookie\Cookie $cookie
*/
public function removeCookieIfEmpty(Cookie $cookie)
{
$cookieValue = $cookie->getValue();
if (!empty($cookieValue)) {
return;
}
$foundCookie = array_filter($this->cookies, function (Cookie $savedCookie) use ($cookie) {
return $savedCookie->getName() === $cookie->getName();
});
if ($foundCookie) {
$index = array_search($foundCookie, $this->cookies);
unset($this->cookies[$index]);
}
}
public function add(Cookie $cookie)
{
// Only allow cookies with set and valid domain, name, value
@@ -93,6 +115,7 @@ public function add(Cookie $cookie)
if ($this->strictMode) {
throw new InvalidCookieException($result);
} else {
$this->removeCookieIfEmpty($cookie);
return false;
}
}

0 comments on commit f9a2553

Please sign in to comment.