/** * Store the cookies from a response. * * Store the cookies that haven't expired. If a cookie has been expired * and is currently stored, it will be removed. * * @param \Cake\Network\Http\Response $response The response to read cookies from * @param string $url The request URL used for default host/path values. * @return void */ public function store(Response $response, $url) { $host = parse_url($url, PHP_URL_HOST); $path = parse_url($url, PHP_URL_PATH); $path = $path ?: '/'; $cookies = $response->cookies(); foreach ($cookies as $name => $cookie) { if (empty($cookie['domain'])) { $cookie['domain'] = $host; } if (empty($cookie['path'])) { $cookie['path'] = $path; } $key = implode(';', [$cookie['name'], $cookie['domain'], $cookie['path']]); $expires = isset($cookie['expires']) ? $cookie['expires'] : false; $expiresTime = false; if ($expires) { $expiresTime = strtotime($expires); } if ($expiresTime && $expiresTime <= time()) { unset($this->_cookies[$key]); continue; } $this->_cookies[$key] = $cookie; } }