public function testParse() { $string = 'foo=bar'; $cookie = new Cookie('foo', 'bar'); $this->object->parse($string); $array = $this->readAttribute($this->object, 'elements'); $this->assertEquals($cookie, $array['foo']); }
protected function parseResponse($response) { // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string if (false !== stripos($response, "HTTP/1.0 200 Connection established\r\n\r\n")) { $response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $response); } list($response_headers, $body) = explode("\r\n\r\n", $response, 2); $header_lines = explode("\r\n", $response_headers); // first line of headers is the HTTP response code $http_response_line = array_shift($header_lines); $code = null; if (preg_match('@^HTTP/[0-9]\\.[0-9] ([0-9]{3})@', $http_response_line, $matches)) { $code = $matches[1]; } $cookies = new CookieCollection(); $headers = new HeaderCollection(); foreach ($header_lines as $line) { list($name, $value) = explode(': ', $line); if ($name == 'Set-Cookie') { $cookies->parse($value); } else { $headers->parse($name, $value); } } return array($code, $headers, $cookies, $body); }