/** * {@inheritdoc} */ public function updateFromResponse(Response $response, $uri = null) { foreach ($response->getHeader('Set-Cookie', false) as $cookie) { $this->set(Cookie::fromString(urldecode($cookie), $uri)); } }
public function testMagicToStringWithMultipleSetCookieHeader() { $headers = array('content-type' => 'text/html; charset=utf-8', 'set-cookie' => array('foo=bar', 'bar=foo')); $expected = 'content-type: text/html; charset=utf-8' . "\n"; $expected .= 'set-cookie: foo=bar' . "\n"; $expected .= 'set-cookie: bar=foo' . "\n\n"; $expected .= 'foo'; $response = new Response('foo', 304, $headers); $this->assertEquals($expected, $response->__toString(), '->__toString() returns the headers and the content as a string'); }
/** * Reads response meta tags to guess content-type charset. * * @param Response $response * * @return Response */ protected function filterResponse($response) { $contentType = $response->getHeader('Content-Type'); if (!$contentType || false === strpos($contentType, 'charset=')) { if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $response->getContent(), $matches)) { $headers = $response->getHeaders(); $headers['Content-Type'] = $contentType . ';charset=' . $matches[1]; $response = new Response($response->getContent(), $response->getStatus(), $headers); } } return parent::filterResponse($response); }
/** * @return $this */ public function assertSuccess() { $this->assertEquals(200, $this->response->getStatusCode()); return $this; }
public function getContent() { $metadata = array('content-type' => $this->getHeader('Content-Type', true, true), 'url' => $this->getUrl()); return $this->getCharsetFront()->convert(parent::getContent(), $metadata); }
public function testMagicToString() { $response = new Response('foo', 304, array('foo' => 'bar')); $this->assertEquals("foo: bar\n\nfoo", $response->__toString(), '->__toString() returns the headers and the content as a string'); }