Example #1
0
 public static function parse($header, $body)
 {
     $response = new self();
     $lines = array_filter(explode("\r\n", $header));
     if (preg_match('#^HTTP/(?P<protocol>[\\d\\.]+)\\s(?P<status>\\d+)\\s(?P<reason>.*?)$#i', array_shift($lines), $match)) {
         $response->protocolVersion = $match['protocol'];
         $response->status = (int) $match['status'];
         $response->reasonPhrase = $match['reason'];
         foreach ($lines as $line) {
             list($name, $value) = explode(':', $line, 2);
             $response->addHeaderToArray($response->headers, trim($name), trim($value), true);
         }
         $response->body = \EasyRequest\stream_for($body);
     }
     return $response;
 }