public function testParsing() { $headerRaw = array('HTTP/1.1 200 OK', 'Date: Wed, 09 Nov 2011 12:38:11 GMT', 'Server: Apache/2.2.17 (Win32) PHP/5.3.8', 'X-Powered-By: PHP/5.3.8', 'Set-Cookie: SID=cre3iuuc0p0s9o8bfnh5lg3fq4; path=/', 'Expires: Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Pragma: no-cache', 'Set-Cookie: login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=serien-loader.philipp.zpintern', 'Content-Length: 3481', 'Content-Type: text/html; charset=utf-8'); $string = implode("\r\n", $headerRaw); // das ist nur damit wir hier kein line-ending verhunzen $header = new Header(); $header->parseFrom($string); $expected = array('Date' => 'Wed, 09 Nov 2011 12:38:11 GMT', 'Server' => 'Apache/2.2.17 (Win32) PHP/5.3.8', 'X-Powered-By' => 'PHP/5.3.8', 'Set-Cookie' => array(0 => 'SID=cre3iuuc0p0s9o8bfnh5lg3fq4; path=/', 1 => 'login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=serien-loader.philipp.zpintern'), 'Expires' => 'Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'no-cache', 'Content-Length' => '3481', 'Content-Type' => 'text/html; charset=utf-8'); $this->assertEquals($expected, $header->getValues()); }
/** * @return Response des Aufrufes */ public function process() { if (!isset($this->url) || $this->url === '') { throw new RequestException('Request kann nicht gesendet werden. URL ist leer'); } //if (curl_getopt($this->ch, CURLOPT_URL) == '') throw new RequestException('Request kann nicht gesendet werden. wurde vorher init() aufgerufen? (CURLOPT_URL nicht gesetzt).'); /* speicher die responseHeaders in unserer variable die wir an die response weitergeben */ $this->setOption(CURLOPT_HEADERFUNCTION, array($this, 'callbackHeader')); $this->responseHeader = NULL; /* Ausführen */ $rawResponse = curl_exec($this->ch); if (curl_error($this->ch) != "") { throw new RequestException(sprintf("Fehler beim Aufruf von URL: '%s' CURL-Error: '%s'", $this->url, curl_error($this->ch)), curl_errno($this->ch)); } try { $this->response = new Response($rawResponse, HTTP\Header::parse($this->responseHeader)); } catch (\Psc\Exception $e) { throw new RequestException('Aus dem Request konnte keine Response erstellt werden. ' . $e->getMessage(), 0, $e); } $this->headers = curl_getinfo($this->ch, CURLINFO_HEADER_OUT); curl_close($this->ch); $this->manager->dispatchEvent(self::EVENT_PROCESSED, array('response' => $this->response, 'headers' => $this->headers), $this); return $rawResponse; }