Ejemplo n.º 1
0
 /**
  * @param ResponseHeader|array|string $headers
  * @return Psc\Net\HTTP\Response
  */
 public static function create($code, $body = NULL, $header = NULL)
 {
     if ($header === NULL) {
         $header = new ResponseHeader($code);
     } elseif (is_array($header)) {
         $header = new ResponseHeader($code, $header);
     } elseif ($header instanceof ResponseHeader) {
     } elseif (is_string($header)) {
         $header = ResponseHeader::parse($header);
     } else {
         throw new \InvalidArgumentException('Header hat ein Falsches Format. ' . Code::varInfo($headers));
     }
     return new static($code, $body, $header);
 }
Ejemplo n.º 2
0
 public function testParsing()
 {
     $headerRaw = $this->headerRaw;
     $string = implode("\r\n", $headerRaw);
     // das ist nur damit wir hier kein line-ending verhunzen
     $header = new ResponseHeader();
     $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' => array('must-revalidate', 'no-cache', 'no-store', 'post-check=0', 'pre-check=0', 'private'), 'Pragma' => array('no-cache'), 'Content-Length' => '3481', 'Content-Type' => 'text/html; charset=utf-8', 'Vary' => 'Accept');
     $this->assertEquals($expected, $header->getValues());
     $header = ResponseHeader::parse($string);
     $this->assertEquals($expected, $header->getValues());
     $testHeader = $this->getMock('Psc\\Net\\HTTP\\ResponseHeader', array('sendPHPHeader'));
     $testHeader->parseFrom($string);
     return $testHeader;
 }