/** * Processes Set-Cookie headers from a request/response pair. * * @param Message\Request $request A request object * @param Message\Response $response A response object */ public function processSetCookieHeaders(Message\Request $request, Message\Response $response) { foreach ($response->getHeader('Set-Cookie', false) as $header) { $cookie = new Cookie(); $cookie->fromSetCookieHeader($header, parse_url($request->getHost(), PHP_URL_HOST)); $this->addCookie($cookie); } }
public function testClearExpiredCookiesRemovesExpiredCookies() { $cookie = new Cookie(); $cookie->setName('SESSION'); $cookie->setValue('asdf'); $cookie->setAttribute(Cookie::ATTR_EXPIRES, 'Fri, 01-Dec-1999 00:00:00 GMT'); $jar = new Jar(); $jar->addCookie($cookie); $jar->clearExpiredCookies(); $this->assertEquals(count($jar->getCookies()), 0); $cookie = new Cookie(); $cookie->setName('SESSION'); $cookie->setValue('asdf'); $cookie->setAttribute(Cookie::ATTR_MAX_AGE, '-60'); $jar = new Jar(); $jar->addCookie($cookie); $jar->clearExpiredCookies(); $this->assertEquals(count($jar->getCookies()), 0); }
public function testMatchesRequestChecksSecureAttribute() { $request = new Message\Request(); $request->setHost('https://example.com'); $cookie = new Cookie(); $cookie->setAttribute(Cookie::ATTR_DOMAIN, 'example.com'); $cookie->setAttribute(Cookie::ATTR_SECURE, null); $this->assertTrue($cookie->matchesRequest($request)); $request = new Message\Request(); $request->setHost('http://example.com'); $this->assertFalse($cookie->matchesRequest($request)); }