Create an EasyRdf_Http_Response object from a HTTP response string
string $responseStr:
public static function fromString($responseStr) {
// First, split body and headers
$matches = preg_split('|(?:\\r?\\n){2}|m', $responseStr, 2);
if ($matches and sizeof($matches) == 2) {
list($headerLines, $body) = $matches;
}
else {
throw new EasyRdf_Exception("Failed to parse HTTP response.");
}
// Split headers part to lines
$headerLines = preg_split('|[\\r\\n]+|m', $headerLines);
$status = array_shift($headerLines);
if (preg_match("|^HTTP/([\\d\\.x]+) (\\d+) ([^\r\n]+)|", $status, $m)) {
$version = $m[1];
$status = $m[2];
$message = $m[3];
}
else {
throw new EasyRdf_Exception("Failed to parse HTTP response status line.");
}
// Process the rest of the header lines
$headers = array();
foreach ($headerLines as $line) {
if (preg_match("|^([\\w-]+):\\s+(.+)\$|", $line, $m)) {
$hName = ucwords(strtolower($m[1]));
$hValue = $m[2];
if (isset($headers[$hName])) {
if (!is_array($headers[$hName])) {
$headers[$hName] = array(
$headers[$hName],
);
}
$headers[$hName][] = $hValue;
}
else {
$headers[$hName] = $hValue;
}
}
}
return new EasyRdf_Http_Response($status, $headers, $body, $version, $message);
}